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);
@Override public byte[] digest() { byte[] output = new byte[digest.getDigestSize()]; digest.doFinal(output, 0); return output; }
private static void hash(Digest d, byte[] input, byte[] output, int outPos) { d.update(input, 0, input.length); d.doFinal(output, outPos); }
static byte[] signature(Digest digest) { byte[] out = new byte[digest.getDigestSize()]; digest.doFinal(out, 0); return out; } }
@Override public byte[] digest() { byte[] dig = new byte[this.digest.getDigestSize()]; this.digest.doFinal(dig, 0); return dig; }
public byte[] getDigest() { byte[] res = new byte[digest.getDigestSize()]; digest.doFinal(res, 0); return res; } }
public static void signPrehash(byte[] sk, int skOff, byte[] ctx, Digest ph, byte[] sig, int sigOff) { byte[] m = new byte[PREHASH_SIZE]; if (PREHASH_SIZE != ph.doFinal(m, 0)) { throw new IllegalArgumentException("ph"); } byte phflag = 0x01; implSign(sk, skOff, ctx, phflag, m, 0, m.length, sig, sigOff); }
private void doHash(byte[] input, byte[] output) { _digest.update(input, 0, input.length); _digest.doFinal(output, 0); }
private byte[] calculateCMSKeyChecksum( byte[] key) { byte[] result = new byte[8]; sha1.update(key, 0, key.length); sha1.doFinal(digest, 0); System.arraycopy(digest, 0, result, 0, 8); return result; }
@Override public byte[] digest() { byte[] dig = new byte[digest.getDigestSize()]; digest.doFinal(dig, 0); return dig; }
public byte[] getDigest() { byte[] res = new byte[digest.getDigestSize()]; digest.doFinal(res, 0); return res; } }
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; }
public byte[] digest() { byte[] result = new byte[digest.getDigestSize()]; digest.doFinal(result, 0); reset(); return result; }
private byte[] calculateCommitment(byte[] w, byte[] message) { byte[] commitment = new byte[digest.getDigestSize()]; digest.update(w, 0, w.length); digest.update(message, 0, message.length); digest.doFinal(commitment, 0); return commitment; } }
@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; }
public static void generatePublicKey(byte[] sk, int skOff, byte[] pk, int pkOff) { Digest d = createDigest(); byte[] h = new byte[d.getDigestSize()]; d.update(sk, skOff, SECRET_KEY_SIZE); d.doFinal(h, 0); byte[] s = new byte[SCALAR_BYTES]; pruneScalar(h, 0, s); scalarMultBaseEncoded(s, pk, pkOff); }
protected void ssl3Complete(Digest d, byte[] ipad, byte[] opad, int padLength) { byte[] master_secret = context.getSecurityParameters().masterSecret; d.update(master_secret, 0, master_secret.length); d.update(ipad, 0, padLength); byte[] tmp = new byte[d.getDigestSize()]; d.doFinal(tmp, 0); d.update(master_secret, 0, master_secret.length); d.update(opad, 0, padLength); d.update(tmp, 0, tmp.length); } }