List of usage examples for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_mgf1
ASN1ObjectIdentifier id_mgf1
To view the source code for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_mgf1.
Click Source Link
From source file:no.difi.sdp.client.internal.CreateCMSDocument.java
License:Apache License
private AlgorithmIdentifier rsaesOaepIdentifier() { AlgorithmIdentifier hash = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256, DERNull.INSTANCE); AlgorithmIdentifier mask = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, hash); AlgorithmIdentifier p_source = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(new byte[0])); ASN1Encodable parameters = new RSAESOAEPparams(hash, mask, p_source); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSAES_OAEP, parameters); }
From source file:org.xipki.common.util.AlgorithmUtil.java
License:Open Source License
static public RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOID) throws NoSuchAlgorithmException { int saltSize; if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOID)) { saltSize = 20;//from w ww. j a v a 2 s . c o m } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID)) { saltSize = 28; } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID)) { saltSize = 32; } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOID)) { saltSize = 48; } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOID)) { saltSize = 64; } else { throw new NoSuchAlgorithmException("unknown digest algorithm " + digestAlgOID); } AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOID, DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); }
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()); }/* w w w . j a v a2 s . c om*/ 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.provider.P11RSAPSSSignatureSpi.java
License:Open Source License
@Override protected void engineSetParameter(final AlgorithmParameterSpec params) throws InvalidParameterException { if (params instanceof PSSParameterSpec) { PSSParameterSpec newParamSpec = (PSSParameterSpec) params; if (originalSpec != null) { if (!DigestFactory.isSameDigest(originalSpec.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm())) { throw new InvalidParameterException( "parameter must be using " + originalSpec.getDigestAlgorithm()); }//w ww.j a v a 2s . c o m } if (!newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !newParamSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId())) { throw new InvalidParameterException("unknown mask generation function specified"); } if (!(newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec)) { throw new InvalidParameterException("unkown MGF parameters"); } MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) newParamSpec.getMGFParameters(); if (!DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm())) { throw new InvalidParameterException( "digest algorithm for MGF should be the same as for PSS parameters."); } Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm()); if (newDigest == null) { throw new InvalidParameterException( "no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm()); } this.engineParams = null; this.paramSpec = newParamSpec; this.mgfDigest = newDigest; this.saltLength = paramSpec.getSaltLength(); this.trailer = getTrailer(paramSpec.getTrailerField()); setupContentDigest(); } else { throw new InvalidParameterException("only PSSParameterSpec supported"); } }
From source file:org.xipki.commons.security.util.AlgorithmUtil.java
License:Open Source License
public static RSASSAPSSparams createPSSRSAParams(final HashAlgoType digestAlg) throws NoSuchAlgorithmException { ParamUtil.requireNonNull("digestAlg", digestAlg); int saltSize = digestAlg.getLength(); AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlg.getOid(), DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); }
From source file:org.xipki.ocsp.client.api.RequestOptions.java
License:Open Source License
static public RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOID) { int saltSize; if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOID)) { saltSize = 20;/*from www . j a va 2s . c o m*/ } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID)) { saltSize = 28; } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID)) { saltSize = 32; } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOID)) { saltSize = 48; } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOID)) { saltSize = 64; } else { throw new RuntimeException("unknown digest algorithm " + digestAlgOID); } AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOID, DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); }
From source file:org.xipki.pki.ocsp.client.api.RequestOptions.java
License:Open Source License
public static RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOid) { int saltSize; if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) { saltSize = 20;// w ww . j av a2 s . c o m } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOid)) { saltSize = 28; } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) { saltSize = 32; } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) { saltSize = 48; } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) { saltSize = 64; } else { throw new RuntimeException("unknown digest algorithm " + digestAlgOid); } AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); }
From source file:org.xipki.security.provider.RSAPSSSignatureSpi.java
License:Open Source License
protected void engineSetParameter(final AlgorithmParameterSpec params) throws InvalidParameterException { if (params instanceof PSSParameterSpec) { PSSParameterSpec newParamSpec = (PSSParameterSpec) params; if (originalSpec != null) { if (DigestFactory.isSameDigest(originalSpec.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()) == false) { throw new InvalidParameterException( "parameter must be using " + originalSpec.getDigestAlgorithm()); }// w ww .j av a 2s . c o m } if ((newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") == false) && (newParamSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()) == false)) { throw new InvalidParameterException("unknown mask generation function specified"); } if ((newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec) == false) { throw new InvalidParameterException("unkown MGF parameters"); } MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) newParamSpec.getMGFParameters(); if (DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()) == false) { throw new InvalidParameterException( "digest algorithm for MGF should be the same as for PSS parameters."); } Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm()); if (newDigest == null) { throw new InvalidParameterException( "no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm()); } this.engineParams = null; this.paramSpec = newParamSpec; this.mgfDigest = newDigest; this.saltLength = paramSpec.getSaltLength(); this.trailer = getTrailer(paramSpec.getTrailerField()); setupContentDigest(); } else { throw new InvalidParameterException("only PSSParameterSpec supported"); } }
From source file:org.xwiki.crypto.signer.internal.factory.BcRsaSsaPssSignerFactory.java
License:Open Source License
@Override protected AlgorithmIdentifier getSignerAlgorithmIdentifier(AsymmetricCipherParameters parameters) { if (parameters instanceof AsymmetricKeyParameters) { AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(X509ObjectIdentifiers.id_SHA1); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSASSA_PSS, DERNull.INSTANCE); } else if (parameters instanceof PssSignerParameters) { PssParameters pssParams = ((PssSignerParameters) parameters).getPssParameters(); BcDigestFactory factory = getDigestFactory(pssParams.getHashAlgorithm()); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSASSA_PSS, new RSASSAPSSparams( factory.getAlgorithmIdentifier(), new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, getDigestFactory(pssParams.getMaskGenAlgorithm()).getAlgorithmIdentifier()), new ASN1Integer( pssParams.getSaltLength() >= 0 ? pssParams.getSaltLength() : factory.getDigestSize()), new ASN1Integer(pssParams.getTrailerField()))); }//from w w w . j a v a 2s . co m throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }