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