Example usage for org.bouncycastle.openssl PKCS8Generator PBE_SHA1_3DES

List of usage examples for org.bouncycastle.openssl PKCS8Generator PBE_SHA1_3DES

Introduction

In this page you can find the example usage for org.bouncycastle.openssl PKCS8Generator PBE_SHA1_3DES.

Prototype

ASN1ObjectIdentifier PBE_SHA1_3DES

To view the source code for org.bouncycastle.openssl PKCS8Generator PBE_SHA1_3DES.

Click Source Link

Usage

From source file:org.albertschmitt.crypto.RSAService.java

License:Open Source License

/**
 * Encrypt the KeyPair with the password and return it as a PEM object.
 *
 * @param keyPair//from   w w  w.j  a va 2 s.c o  m
 *            The RSA Private / Public Key Pair.
 * @param password
 *            The RSA Private Key will be encrypted with this password.
 * @return A PEM object with the encrypted KeyPair..
 * @throws OperatorCreationException
 * @throws PemGenerationException
 */
private PemObject encryptKey(KeyPair keyPair, char[] password)
        throws OperatorCreationException, PemGenerationException {
    final JceOpenSSLPKCS8EncryptorBuilder encryptorBuilder = new JceOpenSSLPKCS8EncryptorBuilder(
            PKCS8Generator.PBE_SHA1_3DES);
    encryptorBuilder.setRandom(new SecureRandom());
    encryptorBuilder.setPasssword(password);
    encryptorBuilder.setIterationCount(10000);
    OutputEncryptor oe = encryptorBuilder.build();
    final JcaPKCS8Generator gen = new JcaPKCS8Generator(keyPair.getPrivate(), oe);
    final PemObject pem = gen.generate();
    return pem;
}

From source file:org.soulwing.credo.service.crypto.bc.BcPKCS8EncryptionService.java

License:Apache License

private OutputEncryptor createPrivateKeyEncryptor(char[] passphrase) {
    try {/*from   w  w w  . j  a v  a 2  s.c om*/
        return new JceOpenSSLPKCS8EncryptorBuilder(PKCS8Generator.PBE_SHA1_3DES).setPasssword(passphrase)
                .setIterationCount(65536).build();
    } catch (OperatorCreationException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.soulwing.credo.service.crypto.bc.BcPrivateKeyWrapper.java

License:Apache License

private OutputEncryptor createPrivateKeyEncryptor() {
    try {/*from w  ww  .j  ava2s .  c om*/
        Validate.notNull(passphrase, "passphrase is required");
        return new JceOpenSSLPKCS8EncryptorBuilder(PKCS8Generator.PBE_SHA1_3DES).setPasssword(passphrase)
                .setIterationCount(100).build();
    } catch (OperatorCreationException ex) {
        throw new RuntimeException(ex);
    }
}