MessageDigestCollector { public byte[] digest(ProtocolVersion version, CipherSuite suite) { try { MessageDigest hash1; MessageDigest hash2 = null; DigestAlgorithm algorithm = AlgorithmResolver.getDigestAlgorithm(version, suite); if (null == algorithm) { hash1 = MessageDigest.getInstance(algorithm.getJavaName()); } else { switch (algorithm) { case SSL_DIGEST: throw new RuntimeException("Unsupported DigestAlgorithm SSL_DIGEST"); case LEGACY: hash1 = MessageDigest.getInstance("MD5"); hash2 = MessageDigest.getInstance("SHA-1"); break; default: hash1 = MessageDigest.getInstance(algorithm.getJavaName()); break; } } hash1.update(stream.toByteArray()); byte[] digest = hash1.digest(); if (hash2 != null) { hash2.update(stream.toByteArray()); byte[] d2 = hash2.digest(); digest = ArrayConverter.concatenate(digest, d2); } return digest; } catch (NoSuchAlgorithmException ex) { throw new UnsupportedOperationException("Unsupported Hash algorithm!"); } } MessageDigestCollector(); void append(byte[] bytes); byte[] digest(ProtocolVersion version, CipherSuite suite); void reset(); byte[] getRawBytes(); void setRawBytes(byte[] rawBytes);  }
@Test public void testDigest() { digest.setRawBytes(testarray); digest.digest(ProtocolVersion.TLS10, CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA); digest.digest(ProtocolVersion.TLS11, CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA); digest.digest(ProtocolVersion.TLS10, CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256); digest.digest(ProtocolVersion.TLS11, CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256); digest.digest(ProtocolVersion.TLS10, CipherSuite.TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384); digest.digest(ProtocolVersion.TLS11, CipherSuite.TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384); digest.digest(ProtocolVersion.TLS10, CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM); digest.digest(ProtocolVersion.TLS11, CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM); digest.digest(ProtocolVersion.TLS10, CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5); digest.digest(ProtocolVersion.TLS11, CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5); digest.digest(ProtocolVersion.TLS10, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8); digest.digest(ProtocolVersion.TLS11, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8); Security.addProvider(new BouncyCastleProvider()); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_GOSTR341001_WITH_28147_CNT_IMIT); digest.digest(ProtocolVersion.TLS12, CipherSuite.TLS_GOSTR341094_WITH_NULL_GOSTR3411); }