Example usage for org.bouncycastle.asn1.pkcs PBEParameter getInstance

List of usage examples for org.bouncycastle.asn1.pkcs PBEParameter getInstance

Introduction

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

Prototype

public static PBEParameter getInstance(Object obj) 

Source Link

Usage

From source file:org.cryptacular.asn.PKCS8PrivateKeyDecoder.java

License:Open Source License

@Override
protected byte[] decryptKey(final byte[] encrypted, final char[] password) {
    final EncryptionScheme scheme;
    final EncryptedPrivateKeyInfo ki = EncryptedPrivateKeyInfo.getInstance(tryConvertPem(encrypted));
    final AlgorithmIdentifier alg = ki.getEncryptionAlgorithm();
    if (PKCSObjectIdentifiers.id_PBES2.equals(alg.getAlgorithm())) {
        scheme = new PBES2EncryptionScheme(PBES2Parameters.getInstance(alg.getParameters()), password);
    } else {/* ww  w.ja  v  a2 s  .c  o  m*/
        scheme = new PBES1EncryptionScheme(PBES1Algorithm.fromOid(alg.getAlgorithm().getId()),
                PBEParameter.getInstance(alg.getParameters()), password);
    }
    return scheme.decrypt(ki.getEncryptedData());
}