public String getLockedDomainPrefix(String token) { byte[] sha = GenericDigestUtils.digest(token); return new String(Base32.encodeBase32(sha)); // a hash } }
public static byte[] digest(String data) { return digest(getBytesUtf8(data)); }
public static byte[] digest(byte[] data) { return getDigest(type).digest(data); }
public static byte[] digest(byte[] data) { return getDigest(type).digest(data); }
/** * Generates unique keys from a master key. * * @param label type of key to derive * @param masterKey master key * @param len length of key needed, less than 20 bytes. 20 bytes are * returned if len is 0. * * @return a derived key of the specified length */ private byte[] deriveKey(byte label, byte[] masterKey, int len) { byte[] base = Bytes.concat(new byte[] { label }, masterKey); byte[] hash = GenericDigestUtils.digest(base); if (len == 0) { return hash; } byte[] out = new byte[len]; System.arraycopy(hash, 0, out, 0, out.length); return out; }
public static byte[] digest(String data) { return digest(getBytesUtf8(data)); }
public static byte[] digest(byte[] data) { return getDigest(type).digest(data); }
/** * Generates unique keys from a master key. * * @param label type of key to derive * @param masterKey master key * @param len length of key needed, less than 20 bytes. 20 bytes are * returned if len is 0. * * @return a derived key of the specified length */ private byte[] deriveKey(byte label, byte[] masterKey, int len) { byte[] base = Bytes.concat(new byte[] { label }, masterKey); byte[] hash = GenericDigestUtils.digest(base); if (len == 0) { return hash; } byte[] out = new byte[len]; System.arraycopy(hash, 0, out, 0, out.length); return out; }
public static byte[] digest(String data) { return digest(getBytesUtf8(data)); }
public static String digestHex(byte[] data) { return Hex.encodeHexString(getDigest(type).digest(data)); }
/** * Generates unique keys from a master key. * * @param label type of key to derive * @param masterKey master key * @param len length of key needed, less than 20 bytes. 20 bytes are * returned if len is 0. * * @return a derived key of the specified length */ private byte[] deriveKey(byte label, byte[] masterKey, int len) { byte[] base = Bytes.concat(new byte[] { label }, masterKey); byte[] hash = GenericDigestUtils.digest(base); if (len == 0) { return hash; } byte[] out = new byte[len]; System.arraycopy(hash, 0, out, 0, out.length); return out; }
public static String digestHex(String data) { return Hex.encodeHexString(digest(getBytesUtf8(data))); }
public static String digestHex(byte[] data) { return Hex.encodeHexString(getDigest(type).digest(data)); }
public static void verifyBodyHash(HttpServletRequest request, String oauthBodyHash) throws InvalidAuthenticationException { // we are doing body hash signing which is not permitted for form-encoded data if (request.getContentType() != null && request.getContentType().contains(OAuth.FORM_ENCODED)) { throw new AuthenticationHandler.InvalidAuthenticationException( "Cannot use oauth_body_hash with a Content-Type of application/x-www-form-urlencoded", null); } else { try { byte[] rawBody = readBody(request); byte[] received = Base64.decodeBase64(CharsetUtil.getUtf8Bytes(oauthBodyHash)); byte[] expected = GenericDigestUtils.digest(rawBody); if (!Arrays.equals(received, expected)) { throw new AuthenticationHandler.InvalidAuthenticationException( "oauth_body_hash failed verification", null); } } catch (IOException ioe) { throw new AuthenticationHandler.InvalidAuthenticationException( "Unable to read content body for oauth_body_hash verification", null); } } }
public static String digestHex(String data) { return Hex.encodeHexString(digest(getBytesUtf8(data))); }