hi ,
i have the following code in C# that i want to replicate in JAVA .
public static string GetPasswordHash(string password)
{
if(password.Length == 0)
return string.Empty;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream, Encoding.Unicode);
bw.Write(password.ToCharArray());
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
byte [] hash = sha.ComputeHash(stream.GetBuffer(), 0, 20);
return Convert.ToBase64String(hash);
}
i tried to do the following but the result was not the same , i got a different encrypted string .
can someone help ?
MessageDigest LHashAlgorithm = MessageDigest.getInstance("SHA");
byte[] LBuffer = password.getBytes();
LHashAlgorithm.update(LBuffer);
byte[] LDigestBuffer = LHashAlgorithm.digest();
String LDigest = new sun.misc.BASE64Encoder().encode(LDigestBuffer);