byte[] getClientTLSCertificateDigest() { //The digest must be SHA256 over the DER encoded certificate. The PEM has the exact DER sequence in hex encoding around the begin and end markers if (tlsClientCertificatePEMBytes != null && clientTLSCertificateDigest == null) { String pemCert = new String(tlsClientCertificatePEMBytes, UTF_8); byte[] derBytes = Base64.getDecoder().decode( pemCert.replaceAll("-+[ \t]*(BEGIN|END)[ \t]+CERTIFICATE[ \t]*-+", "").replaceAll("\\s", "").trim() ); Digest digest = new SHA256Digest(); clientTLSCertificateDigest = new byte[digest.getDigestSize()]; digest.update(derBytes, 0, derBytes.length); digest.doFinal(clientTLSCertificateDigest, 0); } return clientTLSCertificateDigest; }
/** * Generate hash of the given input using the given Digest. * * @param input input data. * @param digest the digest to use for hashing * @return hashed data. */ public static byte[] hash(byte[] input, Digest digest) { byte[] retValue = new byte[digest.getDigestSize()]; digest.update(input, 0, input.length); digest.doFinal(retValue, 0); return retValue; }
@Override public byte[] hash(byte[] input) { Digest digest = getHashDigest(); byte[] retValue = new byte[digest.getDigestSize()]; digest.update(input, 0, input.length); digest.doFinal(retValue, 0); return retValue; }
Digest md = new SHA256Digest() md.reset(); md.update(data, 0, data.length); byte[] hash = new byte[md.getDigestSize()]; md.doFinal(hash, 0);
/** * update the internal digest with the byte b */ public void update( byte b) { digest.update(b); }
void updateDigest(Digest d) { d.update(this.buf, 0, count); } }
public void update( byte[] in, int inOff, int len) { digest.update(in, inOff, len); }
protected void engineUpdate(byte b) throws SignatureException { digest.update(b); }
private void digestAddCounter(long seed) { for (int i = 0; i != 8; i++) { digest.update((byte)seed); seed >>>= 8; } }
protected void engineUpdate(byte b) throws SignatureException { digest.update(b); }
@Override public void update(byte[] input, int inputOffset, int inputLen) { digest.update(input, inputOffset, inputLen); }
public int read() throws IOException { int b = in.read(); if (b >= 0) { digest.update((byte)b); } return b; }
private static void hash(Digest d, byte[] input, byte[] output, int outPos) { d.update(input, 0, input.length); d.doFinal(output, outPos); }
private static void updateDigest(Digest digest, BigInteger bigInteger) { byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger); digest.update(byteArray, 0, byteArray.length); Arrays.fill(byteArray, (byte)0); }
private static void updateDigest(Digest digest, String string) { byte[] byteArray = Strings.toUTF8ByteArray(string); digest.update(byteArray, 0, byteArray.length); Arrays.fill(byteArray, (byte)0); }
static byte[] hash(Digest digest, byte[]... bytes) { for (byte[] b : bytes) { digest.update(b, 0, b.length); } byte[] output = new byte[digest.getDigestSize()]; digest.doFinal(output, 0); return output; }