Created
November 19, 2019 09:15
-
-
Save erancihan/ea31f918061231e7a1675bdfd570a3f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.crypto.SecretKeyFactory; | |
import javax.crypto.spec.PBEKeySpec; | |
import java.nio.charset.StandardCharsets; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.spec.InvalidKeySpecException; | |
import java.security.spec.KeySpec; | |
import java.util.Base64; | |
public class Salter { | |
public static void main(String[] args) | |
{ | |
System.out.println(">: " + salt("password", "[email protected]")); | |
} | |
public static String salt(String A, String B) | |
{ | |
byte[] hash = new byte[0]; | |
try { | |
KeySpec spec = new PBEKeySpec( | |
A.toCharArray(), | |
B.getBytes(StandardCharsets.UTF_8), | |
65536, | |
128 | |
); | |
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); | |
hash = factory.generateSecret(spec).getEncoded(); | |
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) { | |
e.printStackTrace(); | |
} | |
return Base64.getEncoder().encodeToString(hash); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment