Skip to content

Instantly share code, notes, and snippets.

@AppLoidx
Created August 9, 2019 07:18
Show Gist options
  • Save AppLoidx/ed5a0a2ef711ab0f1aa00ae20a713770 to your computer and use it in GitHub Desktop.
Save AppLoidx/ed5a0a2ef711ab0f1aa00ae20a713770 to your computer and use it in GitHub Desktop.
Hashing util static class using Apache Commons
package com.apploidxxx.api.util;
import org.apache.commons.codec.digest.Md5Crypt;
import java.util.Base64;
/**
* @author Arthur Kupriyanov
*/
public class Password {
private static final String salt = Base64.getEncoder().encodeToString("someValue".getBytes());
public static String hash(String password){
return Md5Crypt.md5Crypt((password + salt).getBytes());
}
private static String hash(String password, String anotherEncryptedPassword){
return Md5Crypt.md5Crypt((password + salt).getBytes(), anotherEncryptedPassword);
}
public static boolean isEqual(String rawPassword, String hashedPassword){
return hashedPassword.equals(hash(rawPassword, hashedPassword));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment