@Test public void testVerify() { try { assertTrue(crypto.verify(pemCert, SIGNING_ALGORITHM, sig, plainText)); } catch (CryptoException e) { fail("testVerify should not have thrown exception. Error: " + e.getMessage()); } }
@Override public boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText) throws CryptoException { boolean isVerified = false; if (plainText == null || signature == null || pemCertificate == null) { return false; } if (config.extraLogLevel(10)) { if (null != diagnosticFileDumper) { StringBuilder sb = new StringBuilder(10000); sb.append("plaintext in hex: " + DatatypeConverter.printHexBinary(plainText)); sb.append("\n"); sb.append("signature in hex: " + DatatypeConverter.printHexBinary(signature)); sb.append("\n"); sb.append("PEM cert in hex: " + DatatypeConverter.printHexBinary(pemCertificate)); logger.trace("verify : " + diagnosticFileDumper.createDiagnosticFile(sb.toString())); } } try { X509Certificate certificate = getX509Certificate(pemCertificate); if (certificate != null) { isVerified = validateCertificate(certificate); if (isVerified) { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(certificate); sig.update(plainText); isVerified = sig.verify(signature); } } } catch (InvalidKeyException e) { CryptoException ex = new CryptoException("Cannot verify signature. Error is: " + e.getMessage() + "\r\nCertificate: " + DatatypeConverter.printHexBinary(pemCertificate), e); logger.error(ex.getMessage(), ex); throw ex; } catch (NoSuchAlgorithmException | SignatureException e) { CryptoException ex = new CryptoException("Cannot verify. Signature algorithm is invalid. Error is: " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } return isVerified; }
CryptoPrimitives implements CryptoSuite { @Override public boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText) throws CryptoException { boolean isVerified = false; if (plainText == null || signature == null || pemCertificate == null) { return false; } if (config.extraLogLevel(10)) { if (null != diagnosticFileDumper) { StringBuilder sb = new StringBuilder(10000); sb.append("plaintext in hex: " + DatatypeConverter.printHexBinary(plainText)); sb.append("\n"); sb.append("signature in hex: " + DatatypeConverter.printHexBinary(signature)); sb.append("\n"); sb.append("PEM cert in hex: " + DatatypeConverter.printHexBinary(pemCertificate)); logger.trace("verify : " + diagnosticFileDumper.createDiagnosticFile(sb.toString())); } } try { X509Certificate certificate = getX509Certificate(pemCertificate); if (certificate != null) { isVerified = validateCertificate(certificate); if (isVerified) { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(certificate); sig.update(plainText); isVerified = sig.verify(signature); } } } catch (InvalidKeyException e) { CryptoException ex = new CryptoException("Cannot verify signature. Error is: " + e.getMessage() + "\r\nCertificate: " + DatatypeConverter.printHexBinary(pemCertificate), e); logger.error(ex.getMessage(), ex); throw ex; } catch (NoSuchAlgorithmException | SignatureException e) { CryptoException ex = new CryptoException("Cannot verify. Signature algorithm is invalid. Error is: " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } return isVerified; } }
CryptoPrimitives implements CryptoSuite { @Override public boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText) throws CryptoException { boolean isVerified = false; if (plainText == null || signature == null || pemCertificate == null) { return false; } if (config.extraLogLevel(10)) { if (null != diagnosticFileDumper) { StringBuilder sb = new StringBuilder(10000); sb.append("plaintext in hex: " + DatatypeConverter.printHexBinary(plainText)); sb.append("\n"); sb.append("signature in hex: " + DatatypeConverter.printHexBinary(signature)); sb.append("\n"); sb.append("PEM cert in hex: " + DatatypeConverter.printHexBinary(pemCertificate)); logger.trace("verify : " + diagnosticFileDumper.createDiagnosticFile(sb.toString())); } } try { X509Certificate certificate = getX509Certificate(pemCertificate); if (certificate != null) { isVerified = validateCertificate(certificate); if (isVerified) { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(certificate); sig.update(plainText); isVerified = sig.verify(signature); } } } catch (InvalidKeyException e) { CryptoException ex = new CryptoException("Cannot verify signature. Error is: " + e.getMessage() + "\r\nCertificate: " + DatatypeConverter.printHexBinary(pemCertificate), e); logger.error(ex.getMessage(), ex); throw ex; } catch (NoSuchAlgorithmException | SignatureException e) { CryptoException ex = new CryptoException("Cannot verify. Signature algorithm is invalid. Error is: " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } return isVerified; } CryptoPrimitives(); }
CryptoPrimitives implements CryptoSuite { @Override public boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText) throws CryptoException { boolean isVerified = false; if (plainText == null || signature == null || pemCertificate == null) { return false; } if (config.extraLogLevel(10)) { if (null != diagnosticFileDumper) { StringBuilder sb = new StringBuilder(10000); sb.append("plaintext in hex: " + DatatypeConverter.printHexBinary(plainText)); sb.append("\n"); sb.append("signature in hex: " + DatatypeConverter.printHexBinary(signature)); sb.append("\n"); sb.append("PEM cert in hex: " + DatatypeConverter.printHexBinary(pemCertificate)); logger.trace("verify : " + diagnosticFileDumper.createDiagnosticFile(sb.toString())); } } try { X509Certificate certificate = getX509Certificate(pemCertificate); if (certificate != null) { isVerified = validateCertificate(certificate); if (isVerified) { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(certificate); sig.update(plainText); isVerified = sig.verify(signature); } } } catch (InvalidKeyException e) { CryptoException ex = new CryptoException("Cannot verify signature. Error is: " + e.getMessage() + "\r\nCertificate: " + DatatypeConverter.printHexBinary(pemCertificate), e); logger.error(ex.getMessage(), ex); throw ex; } catch (NoSuchAlgorithmException | SignatureException e) { CryptoException ex = new CryptoException("Cannot verify. Signature algorithm is invalid. Error is: " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } return isVerified; } CryptoPrimitives(); Certificate bytesToCertificate(byte[] certBytes); PrivateKey bytesToPrivateKey(byte[] pemKey); @Override boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText); KeyStore getTrustStore(); void addCACertificateToTrustStore(File caCertPem, String alias); void addCACertificateToTrustStore(byte[] bytes, String alias); @Override void loadCACertificates(Collection<Certificate> certificates); @Override void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes); @Override KeyPair keyGen(); @Override byte[] sign(PrivateKey key, byte[] data); String generateCertificationRequest(String subject, KeyPair pair); @Override byte[] hash(byte[] input); @Override CryptoSuiteFactory getCryptoSuiteFactory(); void init(); @Override Properties getProperties(); byte[] certificateToDER(String certificatePEM); }
CryptoPrimitives implements CryptoSuite { @Override public boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText) throws CryptoException { boolean isVerified = false; if (plainText == null || signature == null || pemCertificate == null) { return false; } if (config.extraLogLevel(10)) { if (null != diagnosticFileDumper) { StringBuilder sb = new StringBuilder(10000); sb.append("plaintext in hex: " + DatatypeConverter.printHexBinary(plainText)); sb.append("\n"); sb.append("signature in hex: " + DatatypeConverter.printHexBinary(signature)); sb.append("\n"); sb.append("PEM cert in hex: " + DatatypeConverter.printHexBinary(pemCertificate)); logger.trace("verify : " + diagnosticFileDumper.createDiagnosticFile(sb.toString())); } } try { X509Certificate certificate = getX509Certificate(pemCertificate); if (certificate != null) { isVerified = validateCertificate(certificate); if (isVerified) { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(certificate); sig.update(plainText); isVerified = sig.verify(signature); } } } catch (InvalidKeyException e) { CryptoException ex = new CryptoException("Cannot verify signature. Error is: " + e.getMessage() + "\r\nCertificate: " + DatatypeConverter.printHexBinary(pemCertificate), e); logger.error(ex.getMessage(), ex); throw ex; } catch (NoSuchAlgorithmException | SignatureException e) { CryptoException ex = new CryptoException("Cannot verify. Signature algorithm is invalid. Error is: " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } return isVerified; } CryptoPrimitives(); Certificate bytesToCertificate(byte[] certBytes); PrivateKey bytesToPrivateKey(byte[] pemKey); @Override boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText); KeyStore getTrustStore(); void addCACertificateToTrustStore(File caCertPem, String alias); void addCACertificateToTrustStore(byte[] bytes, String alias); @Override void loadCACertificates(Collection<Certificate> certificates); @Override void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes); @Override KeyPair keyGen(); @Override byte[] sign(PrivateKey key, byte[] data); String generateCertificationRequest(String subject, KeyPair pair); @Override byte[] hash(byte[] input); @Override CryptoSuiteFactory getCryptoSuiteFactory(); void init(); @Override Properties getProperties(); byte[] certificateToDER(String certificatePEM);  }