Example usage for org.bouncycastle.asn1.pkcs EncryptedPrivateKeyInfo EncryptedPrivateKeyInfo

List of usage examples for org.bouncycastle.asn1.pkcs EncryptedPrivateKeyInfo EncryptedPrivateKeyInfo

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs EncryptedPrivateKeyInfo EncryptedPrivateKeyInfo.

Prototype

public EncryptedPrivateKeyInfo(AlgorithmIdentifier algId, byte[] encoding) 

Source Link

Usage

From source file:org.xwiki.crypto.password.internal.DefaultPrivateKeyPasswordBasedEncryptor.java

License:Open Source License

@Override
public byte[] encrypt(PasswordBasedCipher cipher, PrivateKeyParameters privateKey)
        throws IOException, GeneralSecurityException {
    AlgorithmIdentifier algId;//from ww  w . ja  v a2s  .c o m

    // Optimization
    if (cipher instanceof AbstractBcPBCipher) {
        algId = ((AbstractBcPBCipher) cipher).getPBEParameters();
    } else {
        algId = AlgorithmIdentifier.getInstance(cipher.getEncoded());
    }

    return new EncryptedPrivateKeyInfo(algId, cipher.doFinal(privateKey.getEncoded())).getEncoded();
}