有人可以指出我一个哈希函数(最好是一个实现),这会让我对给定的字符串有 256位字符串输出吗?
非常感谢您提前
答案 0 :(得分: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 将包含消化的字节。