All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.bcpg.OctetArrayBCPGKey Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for the OpenPGP Protocol. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.

There is a newer version: 2.0.9
Show newest version
package org.bouncycastle.bcpg;

import java.io.IOException;
import org.bouncycastle.util.Arrays;

/**
 * Public/Secret BCPGKey which is encoded as an array of octets rather than an MPI.
 */
public abstract class OctetArrayBCPGKey
    extends BCPGObject
    implements BCPGKey
{
    private final byte[] key;

    OctetArrayBCPGKey(int length, BCPGInputStream in)
        throws IOException
    {
        key = new byte[length];
        in.readFully(key);
    }

    OctetArrayBCPGKey(int length, byte[] key)
    {
        if (key.length != length)
        {
            throw new IllegalArgumentException("unexpected key encoding length: expected " + length + " bytes, got " + key.length);
        }
        this.key = new byte[length];
        System.arraycopy(key, 0, this.key, 0, length);
    }

    /**
     * return the standard PGP encoding of the key.
     *
     * @see org.bouncycastle.bcpg.BCPGKey#getEncoded()
     */
    @Override
    public byte[] getEncoded()
    {
        try
        {
            return super.getEncoded();
        }
        catch (IOException e)
        {
            return null;
        }
    }

    @Override
    public String getFormat()
    {
        return "PGP";
    }

    @Override
    public void encode(BCPGOutputStream out)
        throws IOException
    {
        out.write(key);
    }

    public byte[] getKey()
    {
        return Arrays.clone(key);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy