org.bouncycastle.bcpg.OctetArrayBCPGKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpg-jdk14 Show documentation
Show all versions of bcpg-jdk14 Show documentation
The Bouncy Castle Java API for handling the OpenPGP protocol. This jar contains the OpenPGP API for JDK 1.4. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
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()
*/
public byte[] getEncoded()
{
try
{
return super.getEncoded();
}
catch (IOException e)
{
return null;
}
}
public String getFormat()
{
return "PGP";
}
public void encode(BCPGOutputStream out)
throws IOException
{
out.write(key);
}
public byte[] getKey()
{
return Arrays.clone(key);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy