List of usage examples for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_RSASSA_PSS
ASN1ObjectIdentifier id_RSASSA_PSS
To view the source code for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_RSASSA_PSS.
Click Source Link
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 {/*ww w . j av a 2 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.common.util.AlgorithmUtil.java
License:Open Source License
static public AlgorithmIdentifier extractDigesetAlgorithmIdentifier(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException { ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm(); ASN1ObjectIdentifier digestAlgOid;/*from ww w. j av a 2 s.com*/ 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.common.util.AlgorithmUtil.java
License:Open Source License
static public AlgorithmIdentifier buildRSAPSSAlgorithmIdentifier(final ASN1ObjectIdentifier digAlgOid) throws NoSuchAlgorithmException { RSASSAPSSparams params = createPSSRSAParams(digAlgOid); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSASSA_PSS, params); }
From source file:org.xipki.commons.security.bcbugfix.XipkiRSAContentVerifierProviderBuilder.java
License:Open Source License
@Override protected Signer createSigner(AlgorithmIdentifier sigAlgId) throws OperatorCreationException { if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) { try {/*from w ww .j a va2 s .c o m*/ return SignerUtil.createPSSRSASigner(sigAlgId); } catch (XiSecurityException ex) { throw new OperatorCreationException(ex.getMessage(), ex); } } else { AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId); Digest dig = digestProvider.get(digAlg); return new RSADigestSigner(dig); } }
From source file:org.xipki.commons.security.pkcs11.P11ContentSignerBuilder.java
License:Open Source License
private ContentSigner createRSAContentSigner(AlgorithmIdentifier signatureAlgId) throws XiSecurityException, P11TokenException { if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(signatureAlgId.getAlgorithm())) { return new P11RSAPSSContentSigner(cryptService, identityId, signatureAlgId, securityFactory.getRandom4Sign()); } else {//from w ww . ja v a2 s . com return new P11RSAContentSigner(cryptService, identityId, signatureAlgId); } }
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()); }/* w w w . j ava 2 s . 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.pkcs12.SoftTokenContentSignerBuilder.java
License:Open Source License
public ConcurrentContentSigner createSigner(final AlgorithmIdentifier signatureAlgId, final int parallelism, final SecureRandom random) throws OperatorCreationException, NoSuchPaddingException { ParamUtil.requireNonNull("signatureAlgId", signatureAlgId); ParamUtil.requireMin("parallelism", parallelism, 1); List<ContentSigner> signers = new ArrayList<>(parallelism); ASN1ObjectIdentifier algOid = signatureAlgId.getAlgorithm(); final String provName = XiSecurityConstants.PROVIDER_NAME_NSS; if (Security.getProvider(provName) != null && !(key instanceof ECPrivateKey)) { String algoName;/*from w w w . j a va 2 s .c om*/ try { algoName = AlgorithmUtil.getSignatureAlgoName(signatureAlgId); } catch (NoSuchAlgorithmException ex) { throw new OperatorCreationException(ex.getMessage()); } boolean useGivenProvider = true; if (algOid.equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { BcContentSignerBuilder signerBuilder; if (!(key instanceof RSAPrivateKey)) { throw new OperatorCreationException( "unsupported key " + key.getClass().getName() + " for RSAPSS"); } try { AsymmetricKeyParameter keyparam; try { signerBuilder = new RSAContentSignerBuilder(signatureAlgId, true); keyparam = SignerUtil.generateRSAPrivateKeyParameter((RSAPrivateKey) key); } catch (NoSuchAlgorithmException ex) { throw new OperatorCreationException("no such algorithm", ex); } for (int i = 0; i < parallelism; i++) { if (random != null) { signerBuilder.setSecureRandom(random); } ContentSigner signer = signerBuilder.build(keyparam); signers.add(signer); } } catch (Exception ex) { useGivenProvider = false; signers.clear(); } } else { try { for (int i = 0; i < parallelism; i++) { Signature signature = Signature.getInstance(algoName, provName); signature.initSign(key); if (i == 0) { signature.update(new byte[] { 1, 2, 3, 4 }); signature.sign(); } ContentSigner signer = new SignatureSigner(signatureAlgId, signature, key); signers.add(signer); } } catch (Exception ex) { useGivenProvider = false; signers.clear(); } } if (useGivenProvider) { LOG.info("use {} to sign {} signature", provName, algoName); } else { LOG.info("could not use {} to sign {} signature", provName, algoName); } } if (CollectionUtil.isEmpty(signers)) { BcContentSignerBuilder signerBuilder; AsymmetricKeyParameter keyparam; try { if (key instanceof RSAPrivateKey) { keyparam = SignerUtil.generateRSAPrivateKeyParameter((RSAPrivateKey) key); signerBuilder = new RSAContentSignerBuilder(signatureAlgId, false); } else if (key instanceof DSAPrivateKey) { keyparam = DSAUtil.generatePrivateKeyParameter(key); signerBuilder = new DSAContentSignerBuilder(signatureAlgId, AlgorithmUtil.isDSAPlainSigAlg(signatureAlgId)); } else if (key instanceof ECPrivateKey) { keyparam = ECUtil.generatePrivateKeyParameter(key); signerBuilder = new ECDSAContentSignerBuilder(signatureAlgId, AlgorithmUtil.isDSAPlainSigAlg(signatureAlgId)); } else { throw new OperatorCreationException("unsupported key " + key.getClass().getName()); } } catch (InvalidKeyException ex) { throw new OperatorCreationException("invalid key", ex); } catch (NoSuchAlgorithmException ex) { throw new OperatorCreationException("no such algorithm", ex); } for (int i = 0; i < parallelism; i++) { if (random != null) { signerBuilder.setSecureRandom(random); } ContentSigner signer = signerBuilder.build(keyparam); signers.add(signer); } } ConcurrentContentSigner concurrentSigner = new DefaultConcurrentContentSigner(signers, key); if (certificateChain != null) { concurrentSigner.setCertificateChain(certificateChain); } else { concurrentSigner.setPublicKey(publicKey); } return concurrentSigner; }
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 ww w. j ava 2 s. c o 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 boolean isRSASigAlgId(final AlgorithmIdentifier algId) { ParamUtil.requireNonNull("algId", algId); ASN1ObjectIdentifier oid = algId.getAlgorithm(); if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(oid) || PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(oid) || PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(oid) || PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(oid) || PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(oid) || NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224.equals(oid) || NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256.equals(oid) || NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384.equals(oid) || NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512.equals(oid) || PKCSObjectIdentifiers.id_RSASSA_PSS.equals(oid)) { return true; }/*from w w w. ja v a2 s . c o m*/ return false; }
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;//w w w. j av a2 s . 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); }