C#代码:
string str = EncryptToSHA256("sa123");
private static string EncryptToSHA256(string plainPassword)
{
SHA256Managed hasher = new SHA256Managed();
byte[] str = System.Text.Encoding.Unicode.GetBytes(plainPassword);
byte[] byteValue = hasher.ComputeHash(str);
return Convert.ToBase64String(hasher.Hash, Base64FormattingOptions.None);
}
结果是:siD9Gnms7UIWmpJrSEV5eUUmpo/rzrYnxmfi0ZYu8VM=
java实现的代码那位大侠告诉我一下呗
public String computeHash(String input) throws NoSuchAlgorithmException{
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.reset();
byte[] utf8bytes=null;
try{
utf8bytes=input.getBytes("UTF-8");
// digest.update(utf8bytes);
} catch (UnsupportedEncodingException e){
e.printStackTrace();
}
byte[] byteData = digest.digest(utf8bytes);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++){
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString().toUpperCase();
}