Search in sources :

Example 1 with DefaultDigestAlgorithmIdentifierFinder

use of com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder in project LinLong-Java by zhenwei1108.

the class JcaContentSignerBuilder method createPSSParams.

private static RSASSAPSSparams createPSSParams(PSSParameterSpec pssSpec) {
    DigestAlgorithmIdentifierFinder digFinder = new DefaultDigestAlgorithmIdentifierFinder();
    AlgorithmIdentifier digId = digFinder.find(pssSpec.getDigestAlgorithm());
    if (digId.getParameters() == null) {
        digId = new AlgorithmIdentifier(digId.getAlgorithm(), DERNull.INSTANCE);
    }
    AlgorithmIdentifier mgfDig = digFinder.find(((MGF1ParameterSpec) pssSpec.getMGFParameters()).getDigestAlgorithm());
    if (mgfDig.getParameters() == null) {
        mgfDig = new AlgorithmIdentifier(mgfDig.getAlgorithm(), DERNull.INSTANCE);
    }
    return new RSASSAPSSparams(digId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, mgfDig), new ASN1Integer(pssSpec.getSaltLength()), new ASN1Integer(pssSpec.getTrailerField()));
}
Also used : RSASSAPSSparams(com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DigestAlgorithmIdentifierFinder(com.github.zhenwei.pkix.operator.DigestAlgorithmIdentifierFinder) DefaultDigestAlgorithmIdentifierFinder(com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder) DefaultDigestAlgorithmIdentifierFinder(com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 2 with DefaultDigestAlgorithmIdentifierFinder

use of com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder in project LinLong-Java by zhenwei1108.

the class JcaAlgorithmParametersConverter method getAlgorithmIdentifier.

public AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier algorithm, AlgorithmParameterSpec algorithmSpec) throws InvalidAlgorithmParameterException {
    if (algorithmSpec instanceof OAEPParameterSpec) {
        if (algorithmSpec.equals(OAEPParameterSpec.DEFAULT)) {
            return new AlgorithmIdentifier(algorithm, new RSAESOAEPparams(RSAESOAEPparams.DEFAULT_HASH_ALGORITHM, RSAESOAEPparams.DEFAULT_MASK_GEN_FUNCTION, RSAESOAEPparams.DEFAULT_P_SOURCE_ALGORITHM));
        } else {
            OAEPParameterSpec oaepSpec = (OAEPParameterSpec) algorithmSpec;
            PSource pSource = oaepSpec.getPSource();
            if (!oaepSpec.getMGFAlgorithm().equals(OAEPParameterSpec.DEFAULT.getMGFAlgorithm())) {
                throw new InvalidAlgorithmParameterException("only " + OAEPParameterSpec.DEFAULT.getMGFAlgorithm() + " mask generator supported.");
            }
            AlgorithmIdentifier hashAlgorithm = new DefaultDigestAlgorithmIdentifierFinder().find(oaepSpec.getDigestAlgorithm());
            if (hashAlgorithm.getParameters() == null) {
                hashAlgorithm = new AlgorithmIdentifier(hashAlgorithm.getAlgorithm(), DERNull.INSTANCE);
            }
            AlgorithmIdentifier mgf1HashAlgorithm = new DefaultDigestAlgorithmIdentifierFinder().find((((MGF1ParameterSpec) oaepSpec.getMGFParameters()).getDigestAlgorithm()));
            if (mgf1HashAlgorithm.getParameters() == null) {
                mgf1HashAlgorithm = new AlgorithmIdentifier(mgf1HashAlgorithm.getAlgorithm(), DERNull.INSTANCE);
            }
            return new AlgorithmIdentifier(algorithm, new RSAESOAEPparams(hashAlgorithm, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, mgf1HashAlgorithm), new AlgorithmIdentifier(PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(((PSource.PSpecified) pSource).getValue()))));
        }
    }
    throw new InvalidAlgorithmParameterException("unknown parameter spec passed.");
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) RSAESOAEPparams(com.github.zhenwei.core.asn1.pkcs.RSAESOAEPparams) PSource(javax.crypto.spec.PSource) DefaultDigestAlgorithmIdentifierFinder(com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec)

Aggregations

AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 DefaultDigestAlgorithmIdentifierFinder (com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder)2 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)1 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)1 RSAESOAEPparams (com.github.zhenwei.core.asn1.pkcs.RSAESOAEPparams)1 RSASSAPSSparams (com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams)1 DigestAlgorithmIdentifierFinder (com.github.zhenwei.pkix.operator.DigestAlgorithmIdentifierFinder)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)1 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)1 PSource (javax.crypto.spec.PSource)1