是否可以从 MD5 和 Java 恢复消息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15521372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 19:55:26  来源:igfitidea点击:

Is it possible to recover message from MD5 and Java?

javahashmd5

提问by Prasad

I have the following code.

我有以下代码。

String plaintext = "HelloWorld";
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plaintext.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16); 

// Now we need to zero pad it if you actually want the full 32 chars.
while(hashtext.length() < 32 ){
    hashtext = "0"+hashtext;            
}

Now I want to convert it back to the original string. Is it possible?

现在我想将它转换回原始字符串。是否可以?

回答by Andreas Fester

I have tried this. Now I want to convert it back to Original string.

我试过这个。现在我想将它转换回原始字符串。

This is not possible with MD5. It is a one-way hash function.

这对于 MD5 是不可能的。它是一种单向哈希函数

In order to be able to encrypt and decrypt, you need to use an encryption/decryption algorithm like AES.

为了能够加密和解密,您需要使用像AES这样的加密/解密算法。

See Java? Cryptography Architecture (JCA) Reference Guidefor more information.

看到Java了吗?密码体系结构 (JCA) 参考指南了解更多信息。