1

有人可以指出一个哈希函数(最好是一个实现),它可以让我为给定的字符串提供256 位字符串输出吗?

非常感谢您提前

4

1 回答 1

2
MessageDigest md   = MessageDigest.getInstance("SHA-256"); //make sure it exists, there are other algorithms, but I prefer SHA for simple and relatively quick hashing
String strToEncode = "Hello world";
md.update(strToEncode.getBytes("UTF-8")); //I'd rather specify the encoding. It's platform dependent otherwise. 
byte[] digestBuff = md.digest();

digestBuff将包含消化后的字节。

于 2012-06-29T13:22:25.490 回答