Example usage for org.bouncycastle.asn1.pkcs KeyDerivationFunc getAlgorithm

List of usage examples for org.bouncycastle.asn1.pkcs KeyDerivationFunc getAlgorithm

Introduction

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

Prototype

public ASN1ObjectIdentifier getAlgorithm() 

Source Link

Usage

From source file:org.xwiki.crypto.password.internal.kdf.factory.BcPKCS5S2KeyDerivationFunctionFactory.java

License:Open Source License

@Override
public KeyDerivationFunction getInstance(ASN1Encodable parameters) {
    KeyDerivationFunc kdf = KeyDerivationFunc.getInstance(parameters);

    if (!kdf.getAlgorithm().equals(PKCSObjectIdentifiers.id_PBKDF2)) {
        throw new IllegalArgumentException(
                "Illegal algorithm identifier for PBKDF2: " + kdf.getAlgorithm().getId());
    }/*w ww .jav a2 s.  c  o  m*/

    PBKDF2Params params = PBKDF2Params.getInstance(kdf.getParameters());

    return getInstance(
            new PBKDF2Parameters((params.getKeyLength() != null) ? params.getKeyLength().intValue() : -1,
                    params.getIterationCount().intValue(), params.getSalt(),
                    toDigestHint(params.getPseudoRandomFunctionIdentifier())));
}

From source file:org.xwiki.crypto.password.internal.kdf.factory.BcScryptKeyDerivationFunctionFactory.java

License:Open Source License

@Override
public KeyDerivationFunction getInstance(ASN1Encodable parameters) {
    KeyDerivationFunc kdf = KeyDerivationFunc.getInstance(parameters);

    if (!kdf.getAlgorithm().equals(ALG_ID)) {
        throw new IllegalArgumentException(
                "Illegal algorithm identifier for Scrypt: " + kdf.getAlgorithm().getId());
    }//from w ww . jav  a 2  s . com

    ScryptKDFParams params = ScryptKDFParams.getInstance(kdf.getParameters());

    return getInstance(
            new ScryptParameters((params.getKeyLength() != null) ? params.getKeyLength().intValue() : -1,
                    params.getCostParameter().intValue(), params.getParallelizationParameter().intValue(),
                    params.getBlockSize().intValue(), params.getSalt()));
}

From source file:org.xwiki.crypto.password.internal.kdf.factory.DefaultKeyDerivationFunctionFactory.java

License:Open Source License

@Override
public KeyDerivationFunction getInstance(byte[] encoded) {
    KeyDerivationFunc func = KeyDerivationFunc.getInstance(ASN1Sequence.getInstance(encoded));
    KeyDerivationFunctionFactory factory = getFactory(func.getAlgorithm().getId());
    KeyDerivationFunction kdf = getBcInstance(factory, func);
    if (kdf == null) {
        kdf = factory.getInstance(encoded);
    }/*from ww  w  .ja va  2  s . co  m*/
    return kdf;
}

From source file:org.xwiki.crypto.password.internal.kdf.factory.DefaultKeyDerivationFunctionFactory.java

License:Open Source License

@Override
public KeyDerivationFunction getInstance(ASN1Encodable parameters) {
    KeyDerivationFunc func = KeyDerivationFunc.getInstance(parameters);
    return getBcInstance(getFactory(func.getAlgorithm().getId()), func);
}