Example usage for org.bouncycastle.openpgp PGPSecretKey PGPSecretKey

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

Introduction

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

Prototype

public PGPSecretKey(int certificationLevel, PGPKeyPair keyPair, String id,
        PGPDigestCalculator checksumCalculator, PGPSignatureSubpacketVector hashedPcks,
        PGPSignatureSubpacketVector unhashedPcks, PGPContentSignerBuilder certificationSignerBuilder,
        PBESecretKeyEncryptor keyEncryptor) throws PGPException 

Source Link

Document

Construct a PGPSecretKey using the passed in private/public key pair and binding it to the passed in id using a generated certification of certificationLevel.

Usage

From source file:org.elasticsearch.plugins.InstallPluginCommandTests.java

License:Apache License

public PGPSecretKey newSecretKey() throws NoSuchAlgorithmException, NoSuchProviderException, PGPException {
    final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(2048);/*from   www.j  a v a  2 s  .  c  om*/
    final KeyPair pair = kpg.generateKeyPair();
    final PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build()
            .get(HashAlgorithmTags.SHA1);
    final PGPKeyPair pkp = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, pair, new Date());
    return new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, pkp, "example@example.com", sha1Calc, null,
            null, new JcaPGPContentSignerBuilder(pkp.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
            new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5, sha1Calc)
                    .setProvider(new BouncyCastleProvider()).build("passphrase".toCharArray()));
}