The list of methods to do XML Hash are organized into topic(s).
String
calculateHash(String password, String salt) calculate Hash
MessageDigest crypt;
crypt = MessageDigest.getInstance("SHA-1");
crypt.update(password.getBytes());
crypt.update(salt.getBytes());
return DatatypeConverter.printHexBinary(crypt.digest());
String
hash(byte[] bytes) Creates a hex encoded SHA-1 hash.
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.reset();
return DatatypeConverter.printHexBinary(messageDigest.digest(bytes)).toLowerCase();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
String
hash(final String text, final String algorithm) calculates a cryptographic hash function (message digest).
MessageDigest hash;
try {
hash = MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedOperationException("No message digest " + algorithm + ".", e);
byte[] digestBytes = null;
digestBytes = hash.digest(text.getBytes(CHARSET_UTF_8));
...
String
hash(String data, String salt) Hashes a string.
KeySpec keySpec = new PBEKeySpec(data.toCharArray(), DatatypeConverter.parseBase64Binary(salt), ITERATIONS,
KEY_LENGTH);
SecretKeyFactory secretKeyFactory = getSecretKeyFactory();
return DatatypeConverter.printBase64Binary(secretKeyFactory.generateSecret(keySpec).getEncoded());
String
hash512(byte[] data) Create a sha-512 hash of a byte array.
String result = null;
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest.update(data);
byte[] digest = messageDigest.digest();
result = DatatypeConverter.printHexBinary(digest).toLowerCase();
} catch (NoSuchAlgorithmException nsae) {
nsae.printStackTrace();
...
String
hashPass(String plaintext) Given a plaintext password, return the SHA256 hash for storage and verification.
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
System.out.println("ERR: Unable to calculate hash, Algorithm not found.");
return "";
md.update(plaintext.getBytes());
...
String
hashPassword(char[] password, String salt, String hashAlgo) Hash the given password using given algorithm.
char[] saltedPassword = Arrays.copyOf(password, password.length + salt.length());
System.arraycopy(salt.toCharArray(), 0, saltedPassword, password.length, salt.length());
MessageDigest messageDigest = MessageDigest.getInstance(hashAlgo);
byte[] hash = messageDigest.digest(StandardCharsets.UTF_8.encode(CharBuffer.wrap(saltedPassword)).array());
return DatatypeConverter.printHexBinary(hash);
String
hashPassword(String password) Make a hash of the plain text password
try {
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(password.getBytes("UTF-8"));
byte[] bytes = md.digest();
String result = encodeBase64(bytes);
return result.trim();
} catch (NoSuchAlgorithmException nsae) {
throw new IllegalStateException(nsae.getMessage());
...