Search in sources :

Example 11 with RSASSAPSSparams

use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.

the class AlgorithmUtil method getSignatureAlgoName.

public static String getSignatureAlgoName(AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();
    String name = null;
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());
        ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
        name = digestOidToMgf1SigNameMap.get(digestAlgOid);
        if (name == null) {
            throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid);
        }
    } else {
        name = sigAlgOidToNameMap.get(algOid);
    }
    if (name == null) {
        throw new NoSuchAlgorithmException("unsupported signature algorithm " + algOid.getId());
    }
    return name;
}
Also used : RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 12 with RSASSAPSSparams

use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.

the class ScepUtil method extractDigesetAlgorithmIdentifier.

public static ASN1ObjectIdentifier extractDigesetAlgorithmIdentifier(String sigOid, byte[] sigParams) throws NoSuchAlgorithmException {
    requireNonBlank("sigOid", sigOid);
    ASN1ObjectIdentifier algOid = new ASN1ObjectIdentifier(sigOid);
    ASN1ObjectIdentifier digestAlgOid;
    if (PKCSObjectIdentifiers.md5WithRSAEncryption.equals(algOid)) {
        digestAlgOid = PKCSObjectIdentifiers.md5;
    } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigParams);
        digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    } else {
        throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId());
    }
    return digestAlgOid;
}
Also used : RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 13 with RSASSAPSSparams

use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project LinLong-Java by zhenwei1108.

the class DefaultSignatureNameFinder method getAlgorithmName.

/**
 * Return the signature name for the passed in algorithm identifier. For signatures that require
 * parameters, like RSASSA-PSS, this is the best one to use.
 *
 * @param algorithmIdentifier the AlgorithmIdentifier of interest.
 * @return a string representation of the name.
 */
public String getAlgorithmName(AlgorithmIdentifier algorithmIdentifier) {
    ASN1Encodable params = algorithmIdentifier.getParameters();
    if (params != null && !DERNull.INSTANCE.equals(params)) {
        if (algorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
            RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
            AlgorithmIdentifier mgfAlg = rsaParams.getMaskGenAlgorithm();
            if (mgfAlg.getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1)) {
                AlgorithmIdentifier digAlg = rsaParams.getHashAlgorithm();
                ASN1ObjectIdentifier mgfHashOid = AlgorithmIdentifier.getInstance(mgfAlg.getParameters()).getAlgorithm();
                if (mgfHashOid.equals(digAlg.getAlgorithm())) {
                    return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1";
                } else {
                    return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1USING" + getDigestName(mgfHashOid);
                }
            }
            return getDigestName(rsaParams.getHashAlgorithm().getAlgorithm()) + "WITHRSAAND" + mgfAlg.getAlgorithm().getId();
        }
    }
    if (oids.containsKey(algorithmIdentifier.getAlgorithm())) {
        return (String) oids.get(algorithmIdentifier.getAlgorithm());
    }
    return algorithmIdentifier.getAlgorithm().getId();
}
Also used : RSASSAPSSparams(com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 14 with RSASSAPSSparams

use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project LinLong-Java by zhenwei1108.

the class X509SignatureUtil method getSignatureName.

static String getSignatureName(AlgorithmIdentifier sigAlgId) {
    ASN1Encodable params = sigAlgId.getParameters();
    if (params != null && !derNull.equals(params)) {
        if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
            RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
            return getDigestAlgName(rsaParams.getHashAlgorithm().getAlgorithm()) + "withRSAandMGF1";
        }
        if (sigAlgId.getAlgorithm().equals(X9ObjectIdentifiers.ecdsa_with_SHA2)) {
            ASN1Sequence ecDsaParams = ASN1Sequence.getInstance(params);
            return getDigestAlgName((ASN1ObjectIdentifier) ecDsaParams.getObjectAt(0)) + "withECDSA";
        }
    }
    // deal with the "weird" ones.
    String algName = (String) algNames.get(sigAlgId.getAlgorithm());
    if (algName != null) {
        return algName;
    }
    return findAlgName(sigAlgId.getAlgorithm());
}
Also used : ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) RSASSAPSSparams(com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)

Aggregations

RSASSAPSSparams (org.bouncycastle.asn1.pkcs.RSASSAPSSparams)10 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)5 RSASSAPSSparams (com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams)4 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)3 ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)2 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)2 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 MessageDigest (java.security.MessageDigest)2 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)1 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)1 DefaultDigestAlgorithmIdentifierFinder (com.github.zhenwei.pkix.operator.DefaultDigestAlgorithmIdentifierFinder)1 DigestAlgorithmIdentifierFinder (com.github.zhenwei.pkix.operator.DigestAlgorithmIdentifierFinder)1 AsymmetricBlockCipher (org.bouncycastle.crypto.AsymmetricBlockCipher)1 Digest (org.bouncycastle.crypto.Digest)1 RSABlindedEngine (org.bouncycastle.crypto.engines.RSABlindedEngine)1 PSSSigner (org.bouncycastle.crypto.signers.PSSSigner)1 AlgorithmCode (org.xipki.security.AlgorithmCode)1