Search in sources :

Example 1 with AlgorithmIdentifier

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));
        }
    };
}
Also used : PKCS5S2ParametersGenerator(org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator) PBKDF2Parameters(org.xwiki.crypto.password.params.PBKDF2Parameters) KeyDerivationFunc(org.bouncycastle.asn1.pkcs.KeyDerivationFunc) PBKDF2Params(org.xwiki.crypto.password.internal.kdf.PBKDF2Params) AbstractBcDigestFactory(org.xwiki.crypto.internal.digest.factory.AbstractBcDigestFactory) BcDigestFactory(org.xwiki.crypto.internal.digest.factory.BcDigestFactory) AbstractBcPBKDF2(org.xwiki.crypto.password.internal.kdf.AbstractBcPBKDF2) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 2 with AlgorithmIdentifier

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));
}
Also used : PBES2Parameters(org.xwiki.crypto.password.internal.kdf.PBES2Parameters) EncryptionScheme(org.bouncycastle.asn1.pkcs.EncryptionScheme) KeyDerivationFunc(org.bouncycastle.asn1.pkcs.KeyDerivationFunc) AbstractBcKDF(org.xwiki.crypto.password.internal.kdf.AbstractBcKDF) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 3 with AlgorithmIdentifier

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());
}
Also used : PBES2Parameters(org.xwiki.crypto.password.internal.kdf.PBES2Parameters) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 4 with AlgorithmIdentifier

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);
}
Also used : PEMKeyPair(org.bouncycastle.openssl.PEMKeyPair) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 5 with AlgorithmIdentifier

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);
}
Also used : PEMKeyPair(org.bouncycastle.openssl.PEMKeyPair) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)249 IOException (java.io.IOException)144 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)140 SubjectPublicKeyInfo (org.bouncycastle.asn1.x509.SubjectPublicKeyInfo)75 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)71 BigInteger (java.math.BigInteger)60 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)55 X500Name (org.bouncycastle.asn1.x500.X500Name)50 X509Certificate (java.security.cert.X509Certificate)44 Date (java.util.Date)43 ContentSigner (org.bouncycastle.operator.ContentSigner)39 DEROctetString (org.bouncycastle.asn1.DEROctetString)38 OutputStream (java.io.OutputStream)37 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)36 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)34 PrivateKeyInfo (org.bouncycastle.asn1.pkcs.PrivateKeyInfo)33 BcRSAContentSignerBuilder (org.bouncycastle.operator.bc.BcRSAContentSignerBuilder)33 DefaultDigestAlgorithmIdentifierFinder (org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder)31 DefaultSignatureAlgorithmIdentifierFinder (org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder)31 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)28