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;
}
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;
}
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();
}
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());
}
Aggregations