CryptoPrimitives implements CryptoSuite { void setHashAlgorithm(String algorithm) throws InvalidArgumentException { if (isNullOrEmpty(algorithm) || !("SHA2".equals(algorithm) || "SHA3".equals(algorithm))) { throw new InvalidArgumentException("Illegal Hash function family: " + algorithm + " - must be either SHA2 or SHA3"); } hashAlgorithm = algorithm; } 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);  }
@Test (expected = InvalidArgumentException.class) public void testSetHashAlgorithm() throws InvalidArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException { CryptoPrimitives testCrypto = new CryptoPrimitives(); testCrypto.setHashAlgorithm(null); }
@Test (expected = InvalidArgumentException.class) public void testSetHashAlgorithmBadArg() throws InvalidArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException { CryptoPrimitives testCrypto = new CryptoPrimitives(); testCrypto.setHashAlgorithm("FAKE"); }