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

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

Introduction

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

Prototype

public static KeyDerivationFunc getInstance(Object obj) 

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());
    }//  ww  w.j av a  2s.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 .  j a va  2  s. c o m

    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   www  .  j  av  a 2s . com*/
    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);
}

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

License:Open Source License

/**
 * Build a new instance from ASN.1 sequence.
 *
 * @param seq an ASN.1 sequence corresponding to PBES2 parameters.
 *//* w  ww.  j a  v  a 2s  . co m*/
private PBES2Parameters(ASN1Sequence seq) {
    Enumeration e = seq.getObjects();
    ASN1Sequence funcSeq = ASN1Sequence.getInstance(((ASN1Encodable) e.nextElement()).toASN1Primitive());

    if (funcSeq.getObjectAt(0).equals(id_PBKDF2)) {
        func = new KeyDerivationFunc(id_PBKDF2, PBKDF2Params.getInstance(funcSeq.getObjectAt(1)));
    } else {
        func = KeyDerivationFunc.getInstance(funcSeq);
    }

    scheme = EncryptionScheme.getInstance(e.nextElement());
}

From source file:org.xwiki.crypto.password.internal.pbe.AbstractBcPBES2Cipher.java

License:Open Source License

@Override
public AlgorithmIdentifier getPBEParameters() throws IOException {
    KeyDerivationFunc kdfParams;//from  w  w w.  j av  a 2 s  . c  om

    if (getKeyDerivationFunction() instanceof AbstractBcKDF) {
        kdfParams = ((AbstractBcKDF) getKeyDerivationFunction()).getKeyDerivationFunction();
    } else {
        kdfParams = KeyDerivationFunc.getInstance(getKeyDerivationFunction().getEncoded());
    }

    EncryptionScheme scheme = getScheme(getParameters());

    return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBES2, new PBES2Parameters(kdfParams, scheme));
}