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 API for handling the OpenPGP protocol. This jar contains the OpenPGP API for JDK 1.5 to JDK 1.8. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.

There is a newer version: 1.79
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