本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKey.encode方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKey.encode方法的具体用法?Java PGPPublicKey.encode怎么用?Java PGPPublicKey.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKey
的用法示例。
在下文中一共展示了PGPPublicKey.encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializePublicKey
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* Serialize a PGPPublicKey
*
* <p>The reason we're not using {@link PGPPublicKey#getEncoded()} is to use {@link
* ArmoredOutputStream}.
*/
public static byte[] serializePublicKey(PGPPublicKey publicKey) throws IOException {
try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) {
// NOTE: We have to close the ArmoredOutputStream before calling the underlying OutputStream's
// "toByteArray". Failing to do so would result in a truncated serialization as we took the
// byte array before the ArmoredOutputStream wrote all the data.
//
// Even "flushing" the ArmoredOutputStream isn't enough - as there are parts that are only
// written by the ArmoredOutputStream when it is closed: the "-----END PGP PRIVATE KEY
// BLOCK-----" (or similar) footer.
try (ArmoredOutputStream out = new ArmoredOutputStream(byteStream)) {
publicKey.encode(out);
}
return byteStream.toByteArray();
}
}
示例2: exportAscii
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* *********************************************************************************** Exports given public key as
* ASCII armored text.
*
* @param pgpKey key to export
*
* @return ASCII armored key text
*/
public static String exportAscii( PGPPublicKey pgpKey ) throws PGPException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
try ( OutputStream os = new ArmoredOutputStream( out ) )
{
pgpKey.encode( os );
}
catch ( IOException ex )
{
throw new PGPException( "Failed to export PGP key", ex );
}
return out.toString();
}
示例3: getPublicKey
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public Content getPublicKey() throws IOException, PGPException {
PGPSecretKey signKey = readSecretKey();
PGPPublicKey publicKey = signKey.getPublicKey();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (BCPGOutputStream os = new BCPGOutputStream(new ArmoredOutputStream(buffer))) {
publicKey.encode(os);
}
return new Content(new BytesPayload(buffer.toByteArray(), AptMimeTypes.PUBLICKEY));
}