Example usage for org.bouncycastle.openpgp PGPSecretKey encode

List of usage examples for org.bouncycastle.openpgp PGPSecretKey encode

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp PGPSecretKey encode.

Prototype

public void encode(OutputStream outStream) throws IOException 

Source Link

Usage

From source file:com.ginema.crypto.encryption.PGPKeyPairGenerator.java

License:Apache License

private static void exportKeyPair(OutputStream secretOut, OutputStream publicOut, PublicKey publicKey,
        PrivateKey privateKey, String identity, char[] passPhrase, boolean armor)
        throws IOException, InvalidKeyException, NoSuchProviderException, SignatureException, PGPException {
    if (armor) {//from  www  . j  av a 2s  . c o  m
        secretOut = new ArmoredOutputStream(secretOut);
    }

    PGPSecretKey secretKey = new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, PGPPublicKey.RSA_GENERAL,
            publicKey, privateKey, new Date(), identity, PGPEncryptedData.CAST5, passPhrase, null, null,
            new SecureRandom(), "BC");

    secretKey.encode(secretOut);

    secretOut.close();

    if (armor) {
        publicOut = new ArmoredOutputStream(publicOut);
    }

    PGPPublicKey key = secretKey.getPublicKey();

    key.encode(publicOut);

    publicOut.close();
}