/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @since 1.4 */ public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @throws IOException * On error reading from the stream * @since 1.4 */ public static byte[] sha256(final InputStream data) throws IOException { return digest(getSha256Digest(), data); }
protected String digest(String permissionsSegment) { try { MessageDigest digest = DigestUtils.getSha256Digest(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new DigestOutputStream(new NullOutputStream(), digest)); outputStreamWriter.write(getClass().getSimpleName()); outputStreamWriter.write("$"); outputStreamWriter.write(name()); outputStreamWriter.write("/"); outputStreamWriter.write(permissionsSegment); outputStreamWriter.write("["); for (GoDashboardPipeline pipeline : allPipelines()) { outputStreamWriter.write(pipeline.cacheSegment()); outputStreamWriter.write(","); } outputStreamWriter.write("]"); outputStreamWriter.flush(); return Hex.encodeHexString(digest.digest()); } catch (IOException e) { throw new UncheckedIOException(e); } } }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @since 1.4 */ public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @since 1.4 */ public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @since 1.4 */ public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @since 1.4 */ public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @since 1.4 */ public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); }
public static String generateShaIdFromName(String pluginName) { MessageDigest digest = DigestUtils.getSha256Digest(); digest.update(pluginName.getBytes()); return bytesAsHex(digest.digest()).substring(0,12); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @throws IOException * On error reading from the stream * @since 1.4 */ public static byte[] sha256(final InputStream data) throws IOException { return digest(getSha256Digest(), data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @throws IOException * On error reading from the stream * @since 1.4 */ public static byte[] sha256(final InputStream data) throws IOException { return digest(getSha256Digest(), data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @throws IOException * On error reading from the stream * @since 1.4 */ public static byte[] sha256(final InputStream data) throws IOException { return digest(getSha256Digest(), data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @throws IOException * On error reading from the stream * @since 1.4 */ public static byte[] sha256(final InputStream data) throws IOException { return digest(getSha256Digest(), data); }
/** * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. * <p> * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. * </p> * * @param data * Data to digest * @return SHA-256 digest * @throws IOException * On error reading from the stream * @since 1.4 */ public static byte[] sha256(final InputStream data) throws IOException { return digest(getSha256Digest(), data); }
public void verifyRpIdHash(AuthData authData, String domain) { try { byte[] retrievedRpIdHash = authData.getRpIdHash(); byte[] calculatedRpIdHash = DigestUtils.getSha256Digest().digest(domain.getBytes("UTF-8")); log.debug("rpIDHash from Domain HEX {}", Hex.encodeHexString(calculatedRpIdHash)); log.debug("rpIDHash from Assertion HEX {}", Hex.encodeHexString(retrievedRpIdHash)); if (!Arrays.equals(retrievedRpIdHash, calculatedRpIdHash)) { log.warn("hash from domain doesn't match hash from assertion HEX "); throw new Fido2RPRuntimeException("Hashes don't match"); } } catch (UnsupportedEncodingException e) { throw new Fido2RPRuntimeException("This encoding is not supported"); } }
@Override public Digests getDigests(MavenArtifact artifact) throws IOException { try (FileInputStream fin = new FileInputStream(artifact.resolve())) { MessageDigest sha1 = DigestUtils.getSha1Digest(); MessageDigest sha256 = DigestUtils.getSha256Digest(); byte[] buf = new byte[2048]; int len; while ((len=fin.read(buf,0,buf.length)) >= 0) { sha1.update(buf, 0, len); sha256.update(buf, 0, len); } Digests ret = new Digests(); ret.sha1 = new String(Base64.encodeBase64(sha1.digest()), "UTF-8"); ret.sha256 = new String(Base64.encodeBase64(sha256.digest()), "UTF-8"); return ret; } }
private MessageDigest resolveDigester(JWSAlgorithm algorithm) { if (JWSAlgorithm.ES256.equals(algorithm)) { return DigestUtils.getSha256Digest(); } else { throw new Fido2RPRuntimeException("Don't know what to do with " + algorithm); } }
public MessageDigest getDigest(int signatureAlgorithm) { // https://www.iana.org/assignments/cose/cose.xhtml#algorithms switch (signatureAlgorithm) { case -257: { return DigestUtils.getSha256Digest(); } case -65535: { return DigestUtils.getSha1Digest(); } default: { throw new Fido2RPRuntimeException("Unknown mapping "); } } }
private String computeContentHash(HttpRequest request) throws IOException { HttpEntity entity = getEntity( request ); if ( entity == null ) { return DigestUtils.sha256Hex( "" ); } if ( !entity.isRepeatable() ) { throw new IllegalStateException( "Cannot sign AWS requests with non-repeatable entities" ); } final MessageDigest digest = getSha256Digest(); DigestOutputStream digestStream = new DigestOutputStream( DISCARDING_STREAM, digest ); entity.writeTo( digestStream ); return Hex.encodeHexString( digest.digest() ); }
private String optimisedSha256(final List<JsonObject> bodyParts) { notEmpty( bodyParts ); try ( GsonHttpEntity entity = new GsonHttpEntity( gson, bodyParts ) ) { final MessageDigest digest = getSha256Digest(); OutputStream discardingStream = new OutputStream() { @Override public void write(int b) throws IOException { } }; DigestOutputStream digestStream = new DigestOutputStream( discardingStream, digest ); entity.writeTo( digestStream ); return encodeHexString( digest.digest() ); } catch (IOException e) { throw new RuntimeException( "We're mocking IO operations, this should not happen?", e ); } }