public static String getTypeId(String subjectTemplate, String bodyTemplateName) { return CryptoUtil.getHashSHA1(subjectTemplate + bodyTemplateName); } }
public static String getHmacSHA1(String message, String secretKey) { return hmacDigest(message, secretKey, HMAC_SHA1); }
public CSRFHandler() { this(CryptoUtil.generateSecretKey()); }
String shaPassword = CryptoUtil.getHashSHA256(password); if (storedPassword.substring("{SHA256}".length()).equals(shaPassword)) { log.trace("Unsalted SHA-256 hashed password matched for user '{}'", username); String shaPassword = CryptoUtil.getHashSHA1(password); if (storedPassword.substring("{SHA1}".length()).equals(shaPassword)) { log.trace("Unsalted SHA-1 hashed password matched for user '{}'", username); String md5Password = CryptoUtil.getHashMD5(password); if (storedPassword.substring("{MD5}".length()).equals(md5Password)) { log.trace("Unsalted MD5 hashed password matched for user '{}'", username); String cmd5Password = CryptoUtil.getHashMD5(username + password); if (storedPassword.substring("{CMD5}".length()).equals(cmd5Password)) { log.trace("Salted MD5 hashed password matched for user '{}'", username);
/** * Calculates the SHA256 hash of the string. * * @param text * @return sha256 hash of the string */ public static String getHashSHA256(String text) { byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1); return getHashSHA256(bytes); }
/** * Calculates the MD5 hash of the string. * * @param text * @return md5 hash of the string */ public static String getHashMD5(String text) { byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1); return getHashMD5(bytes); }
public static String hmacDigest(String message, String secretKey, String algorithm) { String digest = null; try { SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), algorithm); Mac mac = Mac.getInstance(algorithm); mac.init(key); byte[] bytes = mac.doFinal(message.getBytes(StandardCharsets.US_ASCII)); digest = toHex(bytes); } catch (InvalidKeyException e) { } catch (NoSuchAlgorithmException e) { } return digest; }
String shaPassword = CryptoUtil.getHashSHA256(password); if (storedPassword.substring("{SHA256}".length()).equals(shaPassword)) { log.trace("Unsalted SHA-256 hashed password matched for user '{}'", username); String shaPassword = CryptoUtil.getHashSHA1(password); if (storedPassword.substring("{SHA1}".length()).equals(shaPassword)) { log.trace("Unsalted SHA-1 hashed password matched for user '{}'", username); String md5Password = CryptoUtil.getHashMD5(password); if (storedPassword.substring("{MD5}".length()).equals(md5Password)) { log.trace("Unsalted MD5 hashed password matched for user '{}'", username); String cmd5Password = CryptoUtil.getHashMD5(username + password); if (storedPassword.substring("{CMD5}".length()).equals(cmd5Password)) { log.trace("Salted MD5 hashed password matched for user '{}'", username);
/** * Calculates the SHA256 hash of the byte array. * * @param bytes * @return sha256 hash of the byte array */ public static String getHashSHA256(byte[] bytes) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(bytes, 0, bytes.length); byte[] digest = md.digest(); return toHex(digest); } catch (NoSuchAlgorithmException t) { throw new RuntimeException(t); } }
public static String getHmacSHA256(String message, String secretKey) { return hmacDigest(message, secretKey, HMAC_SHA256); }
public static String getTypeId(String subjectTemplate, String bodyTemplateName) { return CryptoUtil.getHashSHA1(subjectTemplate + bodyTemplateName); } }
@Inject public CSRFHandler() { this(CryptoUtil.generateSecretKey()); }
/** * Calculates the MD5 hash of the byte array. * * @param bytes * @return md5 hash of the byte array */ public static String getHashMD5(byte[] bytes) { try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(bytes, 0, bytes.length); byte[] digest = md.digest(); return toHex(digest); } catch (NoSuchAlgorithmException t) { throw new RuntimeException(t); } }
public static String getHmacMD5(String message, String secretKey) { return hmacDigest(message, secretKey, HMAC_MD5); }
/** * Calculates the SHA1 hash of the string. * * @param text * @return sha1 hash of the string */ public static String getHashSHA1(String text) { byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1); return getHashSHA1(bytes); }
@Inject public CSRFHandler() { this(CryptoUtil.generateSecretKey()); }
/** * Calculates the SHA1 hash of the byte array. * * @param bytes * @return sha1 hash of the byte array */ public static String getHashSHA1(byte[] bytes) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(bytes, 0, bytes.length); byte[] digest = md.digest(); return toHex(digest); } catch (NoSuchAlgorithmException t) { throw new RuntimeException(t); } }
/** * Generates a random secret key. * * @return a random secret key. */ public static String generateSecretKey() { return hmacDigest(UUID.randomUUID().toString(), UUID.randomUUID().toString(), HMAC_SHA256); }
String token = CryptoUtil.hmacDigest(sessionId, secretKey, algorithm); setSessionCsrfToken(context, token); log.debug("Generated '{}' for {} '{}'", PARAMETER, httpSerlvetRequestMethod, context.getRequestUri());
String token = CryptoUtil.hmacDigest(sessionId, secretKey, algorithm); setSessionCsrfToken(context, token); log.debug("Generated '{}' for {} '{}'", PARAMETER, httpSerlvetRequestMethod, context.getRequestUri());