List of usage examples for org.bouncycastle.asn1.pkcs RSASSAPSSparams getHashAlgorithm
public AlgorithmIdentifier getHashAlgorithm()
From source file:org.xipki.common.util.AlgorithmUtil.java
License:Open Source License
static public String getSignatureAlgoName(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException { ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) { return "SHA1withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) { return "SHA224withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) { return "SHA256withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) { return "SHA384withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) { return "SHA512WITHECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) { return "SHA1WITHPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) { return "SHA224WITHPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) { return "SHA256WITHPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) { return "SHA384WITHPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) { return "SHA512WITHPLAIN-ECDSA"; } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) { return "SHA1withDSA"; } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) { return "SHA1withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) { return "SHA224withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) { return "SHA256withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) { return "SHA384withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) { return "SHA512withDSA"; } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) { return "SHA1withRSA"; } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) { return "SHA224withRSA"; } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) { return "SHA256withRSA"; } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) { return "SHA384withRSA"; } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) { return "SHA512withRSA"; } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) { RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters()); ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm(); if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) { return "SHA1withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) { return "SHA256withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) { return "SHA384withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) { return "SHA512withRSAandMGF1"; } else {//from ww w . j a va 2s. c om throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid.getId()); } } else { throw new NoSuchAlgorithmException("unsupported signature algorithm " + algOid.getId()); } }
From source file:org.xipki.common.util.AlgorithmUtil.java
License:Open Source License
static public AlgorithmIdentifier extractDigesetAlgorithmIdentifier(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException { ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); ASN1ObjectIdentifier digestAlgOid;/*from w w w . jav a 2 s . c o m*/ if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) { digestAlgOid = X509ObjectIdentifiers.id_SHA1; } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha224; } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha256; } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha384; } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha512; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) { digestAlgOid = X509ObjectIdentifiers.id_SHA1; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha224; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha256; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha384; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha512; } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) { digestAlgOid = X509ObjectIdentifiers.id_SHA1; } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha224; } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha256; } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha384; } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) { digestAlgOid = NISTObjectIdentifiers.id_sha512; } 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)) { ASN1Encodable asn1Encodable = sigAlgId.getParameters(); RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable); digestAlgOid = param.getHashAlgorithm().getAlgorithm(); } else { throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId()); } return new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE); }
From source file:org.xipki.commons.security.pkcs11.P11RSAPkcsPssParams.java
License:Open Source License
public P11RSAPkcsPssParams(final RSASSAPSSparams asn1Params) { ASN1ObjectIdentifier asn1Oid = asn1Params.getHashAlgorithm().getAlgorithm(); HashAlgoType contentHashAlgo = HashAlgoType.getHashAlgoType(asn1Oid); if (contentHashAlgo == null) { throw new IllegalArgumentException("unsupported hash algorithm " + asn1Oid.getId()); }/*from w w w .jav a 2s . c o m*/ AlgorithmIdentifier mga = asn1Params.getMaskGenAlgorithm(); asn1Oid = mga.getAlgorithm(); if (!PKCSObjectIdentifiers.id_mgf1.equals(asn1Oid)) { throw new IllegalArgumentException("unsupported MGF algorithm " + asn1Oid.getId()); } asn1Oid = AlgorithmIdentifier.getInstance(mga.getParameters()).getAlgorithm(); HashAlgoType mgfHashAlgo = HashAlgoType.getHashAlgoType(asn1Oid); if (mgfHashAlgo == null) { throw new IllegalArgumentException("unsupported MGF hash algorithm " + asn1Oid.getId()); } this.saltLength = asn1Params.getSaltLength().longValue(); BigInteger trailerField = asn1Params.getTrailerField(); if (!RSASSAPSSparams.DEFAULT_TRAILER_FIELD.getValue().equals(trailerField)) { throw new IllegalArgumentException("unsupported trailerField " + trailerField); } switch (contentHashAlgo) { case SHA1: this.hashAlgorithm = P11Constants.CKM_SHA_1; break; case SHA224: this.hashAlgorithm = P11Constants.CKM_SHA224; break; case SHA256: this.hashAlgorithm = P11Constants.CKM_SHA256; break; case SHA384: this.hashAlgorithm = P11Constants.CKM_SHA384; break; case SHA512: this.hashAlgorithm = P11Constants.CKM_SHA512; break; case SHA3_224: this.hashAlgorithm = P11Constants.CKM_SHA3_224; break; case SHA3_256: this.hashAlgorithm = P11Constants.CKM_SHA3_256; break; case SHA3_384: this.hashAlgorithm = P11Constants.CKM_SHA3_384; break; case SHA3_512: this.hashAlgorithm = P11Constants.CKM_SHA3_512; break; default: throw new RuntimeException("should not reach here"); } switch (mgfHashAlgo) { case SHA1: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA1; break; case SHA224: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA224; break; case SHA256: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA256; break; case SHA384: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA384; break; case SHA512: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA512; break; case SHA3_224: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_224; break; case SHA3_256: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_256; break; case SHA3_384: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_384; break; case SHA3_512: this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_512; break; default: throw new RuntimeException("should not reach here"); } }
From source file:org.xipki.commons.security.pkcs11.P11RSAPSSContentSigner.java
License:Open Source License
P11RSAPSSContentSigner(final P11CryptService cryptService, final P11EntityIdentifier identityId, final AlgorithmIdentifier signatureAlgId, final SecureRandom random) throws XiSecurityException, P11TokenException { this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService); this.identityId = ParamUtil.requireNonNull("identityId", identityId); this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId); ParamUtil.requireNonNull("random", random); if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(signatureAlgId.getAlgorithm())) { throw new XiSecurityException("unsupported signature algorithm " + signatureAlgId.getAlgorithm()); }//from ww w . ja v a 2s . c o m RSASSAPSSparams asn1Params = RSASSAPSSparams.getInstance(signatureAlgId.getParameters()); ASN1ObjectIdentifier digestAlgOid = asn1Params.getHashAlgorithm().getAlgorithm(); HashAlgoType hashAlgo = HashAlgoType.getHashAlgoType(digestAlgOid); if (hashAlgo == null) { throw new XiSecurityException("unsupported hash algorithm " + digestAlgOid.getId()); } P11SlotIdentifier slotId = identityId.getSlotId(); P11Slot slot = cryptService.getSlot(slotId); if (slot.supportsMechanism(P11Constants.CKM_RSA_PKCS_PSS)) { this.mechanism = P11Constants.CKM_RSA_PKCS_PSS; this.parameters = new P11RSAPkcsPssParams(asn1Params); Digest digest = SignerUtil.getDigest(hashAlgo); this.outputStream = new DigestOutputStream(digest); } else if (slot.supportsMechanism(P11Constants.CKM_RSA_X_509)) { this.mechanism = P11Constants.CKM_RSA_X_509; this.parameters = null; AsymmetricBlockCipher cipher = new P11PlainRSASigner(); P11RSAKeyParameter keyParam; try { keyParam = P11RSAKeyParameter.getInstance(cryptService, identityId); } catch (InvalidKeyException ex) { throw new XiSecurityException(ex.getMessage(), ex); } PSSSigner pssSigner = SignerUtil.createPSSRSASigner(signatureAlgId, cipher); pssSigner.init(true, new ParametersWithRandom(keyParam, random)); this.outputStream = new PSSSignerOutputStream(pssSigner); } else { switch (hashAlgo) { case SHA1: this.mechanism = P11Constants.CKM_SHA1_RSA_PKCS_PSS; break; case SHA224: this.mechanism = P11Constants.CKM_SHA224_RSA_PKCS_PSS; break; case SHA256: this.mechanism = P11Constants.CKM_SHA256_RSA_PKCS_PSS; break; case SHA384: this.mechanism = P11Constants.CKM_SHA384_RSA_PKCS_PSS; break; case SHA512: this.mechanism = P11Constants.CKM_SHA512_RSA_PKCS_PSS; break; case SHA3_224: this.mechanism = P11Constants.CKM_SHA3_224_RSA_PKCS_PSS; break; case SHA3_256: this.mechanism = P11Constants.CKM_SHA3_256_RSA_PKCS_PSS; break; case SHA3_384: this.mechanism = P11Constants.CKM_SHA3_384_RSA_PKCS_PSS; break; case SHA3_512: this.mechanism = P11Constants.CKM_SHA3_512_RSA_PKCS_PSS; break; default: throw new RuntimeException("should not reach here, unknown HashAlgoType " + hashAlgo); } if (!slot.supportsMechanism(this.mechanism)) { throw new XiSecurityException("unsupported signature algorithm " + PKCSObjectIdentifiers.id_RSASSA_PSS.getId() + " with " + hashAlgo); } this.parameters = new P11RSAPkcsPssParams(asn1Params); this.outputStream = new ByteArrayOutputStream(); } }
From source file:org.xipki.commons.security.util.AlgorithmUtil.java
License:Open Source License
public static String getSignatureAlgoName(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException { ParamUtil.requireNonNull("sigAlgId", sigAlgId); ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) { return "SHA1withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) { return "SHA224withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) { return "SHA256withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) { return "SHA384withECDSA"; } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) { return "SHA512withECDSA"; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_224.equals(algOid)) { return "SHA3-224withECDSA"; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_256.equals(algOid)) { return "SHA3-256withECDSA"; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_384.equals(algOid)) { return "SHA3-384withECDSA"; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_512.equals(algOid)) { return "SHA3-512withECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) { return "SHA1withPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) { return "SHA224withPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) { return "SHA256withPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) { return "SHA384withPLAIN-ECDSA"; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) { return "SHA512withPLAIN-ECDSA"; } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) { return "SHA1withDSA"; } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) { return "SHA1withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) { return "SHA224withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) { return "SHA256withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) { return "SHA384withDSA"; } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) { return "SHA512withDSA"; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_224.equals(algOid)) { return "SHA3-224withDSA"; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_256.equals(algOid)) { return "SHA3-256withDSA"; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_384.equals(algOid)) { return "SHA3-384withDSA"; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_512.equals(algOid)) { return "SHA3-512withDSA"; } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) { return "SHA1withRSA"; } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) { return "SHA224withRSA"; } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) { return "SHA256withRSA"; } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) { return "SHA384withRSA"; } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) { return "SHA512withRSA"; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224.equals(algOid)) { return "SHA3-224withRSA"; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256.equals(algOid)) { return "SHA3-256withRSA"; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384.equals(algOid)) { return "SHA3-384withRSA"; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512.equals(algOid)) { return "SHA3-512withRSA"; } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) { RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters()); ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm(); if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) { return "SHA1withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) { return "SHA256withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) { return "SHA384withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) { return "SHA512withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha3_224.equals(digestAlgOid)) { return "SHA3-224withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha3_256.equals(digestAlgOid)) { return "SHA3-256withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha3_384.equals(digestAlgOid)) { return "SHA3-384withRSAandMGF1"; } else if (NISTObjectIdentifiers.id_sha3_512.equals(digestAlgOid)) { return "SHA3-512withRSAandMGF1"; } else {//from w w w . ja v a2 s .co m throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid.getId()); } } else { throw new NoSuchAlgorithmException("unsupported signature algorithm " + algOid.getId()); } }
From source file:org.xipki.commons.security.util.AlgorithmUtil.java
License:Open Source License
public static AlgorithmIdentifier extractDigesetAlgId(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException { ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); ASN1ObjectIdentifier digestAlgOid;//from w ww .j a v a2s . c o m if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) { ASN1Encodable asn1Encodable = sigAlgId.getParameters(); RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable); digestAlgOid = param.getHashAlgorithm().getAlgorithm(); } else { HashAlgoType digestAlg; if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) { digestAlg = HashAlgoType.SHA1; } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) { digestAlg = HashAlgoType.SHA224; } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) { digestAlg = HashAlgoType.SHA256; } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) { digestAlg = HashAlgoType.SHA384; } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) { digestAlg = HashAlgoType.SHA512; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_224.equals(algOid)) { digestAlg = HashAlgoType.SHA3_224; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_256.equals(algOid)) { digestAlg = HashAlgoType.SHA3_256; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_384.equals(algOid)) { digestAlg = HashAlgoType.SHA3_384; } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_512.equals(algOid)) { digestAlg = HashAlgoType.SHA3_512; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) { digestAlg = HashAlgoType.SHA1; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) { digestAlg = HashAlgoType.SHA224; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) { digestAlg = HashAlgoType.SHA256; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) { digestAlg = HashAlgoType.SHA384; } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) { digestAlg = HashAlgoType.SHA512; } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) { digestAlg = HashAlgoType.SHA1; } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) { digestAlg = HashAlgoType.SHA224; } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) { digestAlg = HashAlgoType.SHA256; } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) { digestAlg = HashAlgoType.SHA384; } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) { digestAlg = HashAlgoType.SHA512; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_224.equals(algOid)) { digestAlg = HashAlgoType.SHA3_224; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_256.equals(algOid)) { digestAlg = HashAlgoType.SHA3_256; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_384.equals(algOid)) { digestAlg = HashAlgoType.SHA3_384; } else if (NISTObjectIdentifiers.id_dsa_with_sha3_512.equals(algOid)) { digestAlg = HashAlgoType.SHA3_512; } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) { digestAlg = HashAlgoType.SHA1; } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) { digestAlg = HashAlgoType.SHA224; } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) { digestAlg = HashAlgoType.SHA256; } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) { digestAlg = HashAlgoType.SHA384; } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) { digestAlg = HashAlgoType.SHA512; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224.equals(algOid)) { digestAlg = HashAlgoType.SHA3_224; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256.equals(algOid)) { digestAlg = HashAlgoType.SHA3_256; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384.equals(algOid)) { digestAlg = HashAlgoType.SHA3_384; } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512.equals(algOid)) { digestAlg = HashAlgoType.SHA3_512; } else { throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId()); } digestAlgOid = digestAlg.getOid(); } return new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE); }
From source file:org.xipki.ocsp.server.impl.ResponderSigner.java
License:Open Source License
private static String getSignatureAlgorithmName(final AlgorithmIdentifier sigAlgId) { ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid) == false) { return algOid.getId(); }/*from w w w . j a v a 2s . c o m*/ ASN1Encodable asn1Encodable = sigAlgId.getParameters(); RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable); ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm(); return digestAlgOid.getId() + "WITHRSAANDMGF1"; }
From source file:org.xipki.pki.ocsp.server.impl.ResponderSigner.java
License:Open Source License
private static String getSignatureAlgorithmName(final AlgorithmIdentifier sigAlgId) { ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) { return algOid.getId(); }// w w w. j a va2 s . c o m ASN1Encodable asn1Encodable = sigAlgId.getParameters(); RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable); ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm(); return digestAlgOid.getId() + "WITHRSAANDMGF1"; }
From source file:org.xipki.pki.scep.util.ScepUtil.java
License:Open Source License
public static ASN1ObjectIdentifier extractDigesetAlgorithmIdentifier(final String sigOid, final byte[] sigParams) throws NoSuchAlgorithmException { ParamUtil.requireNonBlank("sigOid", sigOid); ASN1ObjectIdentifier algOid = new ASN1ObjectIdentifier(sigOid); ASN1ObjectIdentifier digestAlgOid;//from w w w .j a v a 2s. c o m 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; }
From source file:org.xwiki.crypto.signer.internal.factory.BcRsaSsaPssSignerFactory.java
License:Open Source License
@Override public Signer getInstance(boolean forSigning, CipherParameters parameters, byte[] encoded) { AlgorithmIdentifier algId = AlgorithmIdentifier.getInstance(encoded); ASN1Encodable algParams = algId.getParameters(); if (DERNull.INSTANCE.equals(algParams)) { return getInstance(forSigning, parameters); } else {/*from ww w. ja v a 2 s.co m*/ RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(algId.getParameters()); if (parameters instanceof AsymmetricKeyParameters) { return getInstance(forSigning, new PssSignerParameters((AsymmetricKeyParameters) parameters, pssParams.getHashAlgorithm().getAlgorithm().getId(), AlgorithmIdentifier.getInstance(pssParams.getMaskGenAlgorithm().getParameters()) .getAlgorithm().getId(), pssParams.getSaltLength().intValue(), pssParams.getTrailerField().intValue())); } } throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }