I'm am looking to implement in go, the following code written in Java.
I have not been able to find any apis or modules for this. Is it possible to achieve this, did I just not the right resources? How are we doing secure hashing in go?
Thanks.
/**
* Encrypts the given password with a salt
*
* @param password The password string to be encrypted
* @param salt A randomly generated salt for the password encryption
* @return The byte[] containing the encrypted password
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
public static byte[] getEncryptedPassword(String password, byte[] salt)
throws NoSuchAlgorithmException, InvalidKeySpecException {
String algorithm = "PBKDF2WithHmacSHA1";
int derivedKeyLength = 160;
// The NIST recommends at least 1,000 iterations:
//
http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf int iterations = 20000;
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, derivedKeyLength);
SecretKeyFactory f = SecretKeyFactory.getInstance(algorithm);
return f.generateSecret(spec).getEncoded();
}