/** * Creates a hash using a specific digest algorithm and a provider. * @param data the message of which you want to create a hash * @param hashAlgorithm the algorithm used to create the hash * @param provider the provider used to create the hash * @return the hash * @throws GeneralSecurityException * @throws IOException */ public static byte[] digest(InputStream data, String hashAlgorithm, String provider) throws GeneralSecurityException, IOException { MessageDigest messageDigest = getMessageDigest(hashAlgorithm, provider); return digest(data, messageDigest); }
/** * Creates an ExternalSignature instance * @param pk a PrivateKey object * @param hashAlgorithm the hash algorithm (e.g. "SHA-1", "SHA-256",...) * @param provider the security provider (e.g. "BC") */ public PrivateKeySignature(PrivateKey pk, String hashAlgorithm, String provider) { this.pk = pk; this.provider = provider; this.hashAlgorithm = DigestAlgorithms.getDigest(DigestAlgorithms.getAllowedDigests(hashAlgorithm)); encryptionAlgorithm = pk.getAlgorithm(); if (encryptionAlgorithm.startsWith("EC")) { encryptionAlgorithm = "ECDSA"; } }
/** * Creates a MessageDigest object that can be used to create a hash. * @param hashAlgorithm the algorithm you want to use to create a hash * @param provider the provider you want to use to create the hash * @return a MessageDigest object * @throws NoSuchAlgorithmException * @throws NoSuchProviderException * @throws GeneralSecurityException */ public static MessageDigest getMessageDigest(String hashAlgorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { if (provider == null || provider.startsWith("SunPKCS11") || provider.startsWith("SunMSCAPI")) return MessageDigest.getInstance(DigestAlgorithms.normalizeDigestName(hashAlgorithm)); else return MessageDigest.getInstance(hashAlgorithm, provider); }
public static MessageDigest getMessageDigestFromOid(String digestOid, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { return getMessageDigest(getDigest(digestOid), provider); }
AlgorithmIdentifier ai2 = cerv2.getHashAlgorithm(); byte[] enc2 = signCert.getEncoded(); MessageDigest m2 = new BouncyCastleDigest().getMessageDigest(DigestAlgorithms.getDigest(ai2.getAlgorithm().getId())); byte[] signCertHash = m2.digest(enc2); byte[] hs2 = cerv2.getCertHash(); TimeStampTokenInfo info = timeStampToken.getTimeStampInfo(); String algOID = info.getMessageImprintAlgOID().getId(); messageDigest = DigestAlgorithms.getMessageDigestFromOid(algOID, null); messageDigest = DigestAlgorithms.getMessageDigest("SHA1", provider); messageDigest = DigestAlgorithms.getMessageDigest(getHashAlgorithm(), provider); encContDigest = DigestAlgorithms.getMessageDigest(getHashAlgorithm(), provider);
public MessageDigest getMessageDigest(String hashAlgorithm) throws GeneralSecurityException { String oid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (oid == null) throw new NoSuchAlgorithmException(hashAlgorithm);
this.interfaceDigest = interfaceDigest; digestAlgorithmOid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (digestAlgorithmOid == null) throw new NoSuchAlgorithmException(MessageLocalization.getComposedMessage("unknown.hash.algorithm.1", hashAlgorithm)); messageDigest = DigestAlgorithms.getMessageDigest(getHashAlgorithm(), provider);
/** * Returns the name of the digest algorithm, e.g. "SHA256". * @return the digest algorithm name, e.g. "SHA256" */ public String getHashAlgorithm() { return DigestAlgorithms.getDigest(digestAlgorithmOid); }
public MessageDigest getMessageDigest(String hashAlgorithm) throws GeneralSecurityException{ return DigestAlgorithms.getMessageDigest(hashAlgorithm, provider); } }
byte hash[] = DigestAlgorithms.digest(data, externalDigest.getMessageDigest(hashAlgorithm)); byte[] ocsp = null; if (chain.length >= 2 && ocspClient != null) {
AlgorithmIdentifier ai2 = cerv2.getHashAlgorithm(); byte[] enc2 = signCert.getEncoded(); MessageDigest m2 = new BouncyCastleDigest().getMessageDigest(DigestAlgorithms.getDigest(ai2.getAlgorithm().getId())); byte[] signCertHash = m2.digest(enc2); byte[] hs2 = cerv2.getCertHash(); TimeStampTokenInfo info = timeStampToken.getTimeStampInfo(); String algOID = info.getMessageImprintAlgOID().getId(); messageDigest = DigestAlgorithms.getMessageDigestFromOid(algOID, null); messageDigest = DigestAlgorithms.getMessageDigest("SHA1", provider); messageDigest = DigestAlgorithms.getMessageDigest(getHashAlgorithm(), provider); encContDigest = DigestAlgorithms.getMessageDigest(getHashAlgorithm(), provider);
public static MessageDigest getMessageDigestFromOid(String digestOid, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { return getMessageDigest(getDigest(digestOid), provider); }
public MessageDigest getMessageDigest(String hashAlgorithm) throws GeneralSecurityException { String oid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (oid == null) throw new NoSuchAlgorithmException(hashAlgorithm);
this.interfaceDigest = interfaceDigest; digestAlgorithmOid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (digestAlgorithmOid == null) throw new NoSuchAlgorithmException(MessageLocalization.getComposedMessage("unknown.hash.algorithm.1", hashAlgorithm)); messageDigest = DigestAlgorithms.getMessageDigest(getHashAlgorithm(), provider);
/** * Returns the name of the digest algorithm, e.g. "SHA256". * @return the digest algorithm name, e.g. "SHA256" */ public String getHashAlgorithm() { return DigestAlgorithms.getDigest(digestAlgorithmOid); }
public MessageDigest getMessageDigest(String hashAlgorithm) throws GeneralSecurityException{ return DigestAlgorithms.getMessageDigest(hashAlgorithm, provider); } }
byte hash[] = DigestAlgorithms.digest(data, externalDigest.getMessageDigest(hashAlgorithm)); byte[] ocsp = null; if (chain.length >= 2 && ocspClient != null) {
/** * Creates a hash using a specific digest algorithm and a provider. * @param data the message of which you want to create a hash * @param hashAlgorithm the algorithm used to create the hash * @param provider the provider used to create the hash * @return the hash * @throws GeneralSecurityException * @throws IOException */ public static byte[] digest(InputStream data, String hashAlgorithm, String provider) throws GeneralSecurityException, IOException { MessageDigest messageDigest = getMessageDigest(hashAlgorithm, provider); return digest(data, messageDigest); }
/** * Creates an ExternalSignature instance * @param pk a PrivateKey object * @param hashAlgorithm the hash algorithm (e.g. "SHA-1", "SHA-256",...) * @param provider the security provider (e.g. "BC") */ public PrivateKeySignature(PrivateKey pk, String hashAlgorithm, String provider) { this.pk = pk; this.provider = provider; this.hashAlgorithm = DigestAlgorithms.getDigest(DigestAlgorithms.getAllowedDigests(hashAlgorithm)); encryptionAlgorithm = pk.getAlgorithm(); if (encryptionAlgorithm.startsWith("EC")) { encryptionAlgorithm = "ECDSA"; } }
SignaturePolicyIdentifier toSignaturePolicyIdentifier() { String algId = DigestAlgorithms.getAllowedDigests(this.policyDigestAlgorithm); if (algId == null || algId.length() == 0) { throw new IllegalArgumentException("Invalid policy hash algorithm"); } SignaturePolicyIdentifier signaturePolicyIdentifier = null; SigPolicyQualifierInfo spqi = null; if (this.policyUri != null && this.policyUri.length() > 0) { spqi = new SigPolicyQualifierInfo(PKCSObjectIdentifiers.id_spq_ets_uri, new DERIA5String(this.policyUri)); } SigPolicyQualifiers qualifiers = new SigPolicyQualifiers(new SigPolicyQualifierInfo[] {spqi}); signaturePolicyIdentifier = new SignaturePolicyIdentifier(new SignaturePolicyId(DERObjectIdentifier.getInstance(new DERObjectIdentifier(this.policyIdentifier.replace("urn:oid:", ""))), new OtherHashAlgAndValue(new AlgorithmIdentifier(algId), new DEROctetString(this.policyHash)), qualifiers)); return signaturePolicyIdentifier; } }