use of com.android.apksig.internal.pkcs7.AlgorithmIdentifier in project xwiki-commons by xwiki.
the class BcPKCS5S2KeyDerivationFunctionFactory method getInstance.
@Override
public KeyDerivationFunction getInstance(KeyDerivationFunctionParameters params) {
if (!(params instanceof PBKDF2Parameters)) {
throw new IllegalArgumentException("Invalid parameter used for PKCS5S2 function: " + params.getClass().getName());
}
PBKDF2Parameters kdfParams = (PBKDF2Parameters) params;
PKCS5S2ParametersGenerator generator;
BcDigestFactory factory = null;
if (kdfParams.getPseudoRandomFuntionHint() != null) {
factory = this.getDigestFactory(kdfParams.getPseudoRandomFuntionHint());
generator = new PKCS5S2ParametersGenerator(factory.getDigestInstance());
} else {
generator = new PKCS5S2ParametersGenerator();
}
return new AbstractBcPBKDF2(generator, (PBKDF2Parameters) params, (factory != null) ? toHmacAlgId(factory.getAlgorithmIdentifier()) : HMAC_SHA1) {
@Override
public KeyDerivationFunc getKeyDerivationFunction() {
PBKDF2Parameters parameters = (PBKDF2Parameters) getParameters();
AlgorithmIdentifier algId = getPRFAlgorithmIdentifier();
return new KeyDerivationFunc(PKCSObjectIdentifiers.id_PBKDF2, (isKeySizeOverwritten()) ? new PBKDF2Params(parameters.getSalt(), parameters.getIterationCount(), algId) : new PBKDF2Params(parameters.getSalt(), parameters.getIterationCount(), parameters.getKeySize(), algId));
}
};
}
use of com.android.apksig.internal.pkcs7.AlgorithmIdentifier in project xwiki-commons by xwiki.
the class AbstractBcPBES2Cipher method getPBEParameters.
@Override
public AlgorithmIdentifier getPBEParameters() throws IOException {
KeyDerivationFunc kdfParams;
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));
}
use of com.android.apksig.internal.pkcs7.AlgorithmIdentifier in project xwiki-commons by xwiki.
the class AbstractBcPBES2CipherFactory method getInstance.
@Override
public PasswordBasedCipher getInstance(boolean forEncryption, byte[] password, ASN1Encodable parameters) {
AlgorithmIdentifier alg = AlgorithmIdentifier.getInstance(parameters);
if (!alg.getAlgorithm().equals(PKCSObjectIdentifiers.id_PBES2)) {
throw new IllegalArgumentException("Illegal algorithm identifier for PBES2: " + alg.getAlgorithm().getId());
}
PBES2Parameters params = PBES2Parameters.getInstance(alg.getParameters());
return getInstance(forEncryption, password, params.getKeyDerivationFunc(), params.getEncryptionScheme());
}
use of com.android.apksig.internal.pkcs7.AlgorithmIdentifier in project sshj by hierynomus.
the class DSAPrivateKeyInfoKeyPairConverter method getKeyPair.
/**
* Get PEM Key Pair calculating DSA Public Key from DSA Private Key Information
*
* @param privateKeyInfo DSA Private Key Information
* @return PEM Key Pair
* @throws IOException Thrown on Public Key parsing failures
*/
@Override
public PEMKeyPair getKeyPair(final PrivateKeyInfo privateKeyInfo) throws IOException {
Objects.requireNonNull(privateKeyInfo, "Private Key Info required");
final AlgorithmIdentifier algorithmIdentifier = privateKeyInfo.getPrivateKeyAlgorithm();
final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();
if (X9ObjectIdentifiers.id_dsa.equals(algorithm)) {
logger.debug("DSA Algorithm Found [{}]", algorithm);
} else {
throw new IllegalArgumentException(String.format("DSA Algorithm OID required [%s]", algorithm));
}
final ASN1Integer encodedPublicKey = getEncodedPublicKey(privateKeyInfo);
final SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, encodedPublicKey);
return new PEMKeyPair(subjectPublicKeyInfo, privateKeyInfo);
}
use of com.android.apksig.internal.pkcs7.AlgorithmIdentifier in project sshj by hierynomus.
the class ECDSAPrivateKeyInfoKeyPairConverter method getKeyPair.
/**
* Get PEM Key Pair calculating ECDSA Public Key from ECDSA Private Key Information
*
* @param privateKeyInfo ECDSA Private Key Information
* @return PEM Key Pair
* @throws IOException Thrown on Public Key parsing failures
*/
@Override
public PEMKeyPair getKeyPair(final PrivateKeyInfo privateKeyInfo) throws IOException {
Objects.requireNonNull(privateKeyInfo, "Private Key Info required");
final AlgorithmIdentifier algorithmIdentifier = privateKeyInfo.getPrivateKeyAlgorithm();
final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();
if (X9ObjectIdentifiers.id_ecPublicKey.equals(algorithm)) {
logger.debug("ECDSA Algorithm Found [{}]", algorithm);
} else {
throw new IllegalArgumentException(String.format("ECDSA Algorithm OID required [%s]", algorithm));
}
final byte[] encodedPublicKey = getEncodedPublicKey(privateKeyInfo);
final SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, encodedPublicKey);
return new PEMKeyPair(subjectPublicKeyInfo, privateKeyInfo);
}
Aggregations