/** * 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); }
/** * 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 static MessageDigest getMessageDigestFromOid(String digestOid, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { return getMessageDigest(getDigest(digestOid), provider); }
public static MessageDigest getMessageDigestFromOid(String digestOid, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { return getMessageDigest(getDigest(digestOid), provider); }
/** * 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 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"; } }
/** * Checks if the timestamp refers to this document. * @return true if it checks false otherwise * @throws GeneralSecurityException on error * @since 2.1.6 */ public boolean verifyTimestampImprint() throws GeneralSecurityException { if (timeStampToken == null) return false; TimeStampTokenInfo info = timeStampToken.getTimeStampInfo(); MessageImprint imprint = info.toASN1Structure().getMessageImprint(); String algOID = info.getMessageImprintAlgOID().getId(); byte[] md = new BouncyCastleDigest().getMessageDigest(DigestAlgorithms.getDigest(algOID)).digest(digest); byte[] imphashed = imprint.getHashedMessage(); boolean res = Arrays.equals(md, imphashed); return res; }
/** * Checks if the timestamp refers to this document. * @return true if it checks false otherwise * @throws GeneralSecurityException on error * @since 2.1.6 */ public boolean verifyTimestampImprint() throws GeneralSecurityException { if (timeStampToken == null) return false; TimeStampTokenInfo info = timeStampToken.getTimeStampInfo(); MessageImprint imprint = info.toASN1Structure().getMessageImprint(); String algOID = info.getMessageImprintAlgOID().getId(); byte[] md = new BouncyCastleDigest().getMessageDigest(DigestAlgorithms.getDigest(algOID)).digest(digest); byte[] imphashed = imprint.getHashedMessage(); boolean res = Arrays.equals(md, imphashed); return res; }
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();
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();