java中的MD5算法解密

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18615458/
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-08-12 09:32:33  来源:igfitidea点击:

MD5 algorithm Decryption in java

javaalgorithmencryptionmd5

提问by subodh

Is it possible to decrypt the below code? below is my method where we are encrypting the String values. If it is decrypt able please guide me how to do that, as per my understanding MD5 algorithm is not decrypt able but for now my job is to find the way to decrypt it. Please provide your valuable opinion to get it done.

是否可以解密以下代码?下面是我加密字符串值的方法。如果它可以解密,请指导我怎么做,根据我的理解,MD5 算法不能解密,但现在我的工作是找到解密它的方法。请提供您的宝贵意见以完成它。

public static String encryptPassword(final String password) {
        if (MyUtil.isEmpty(password)) {
            return null;
        }
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
            digest.update(password.getBytes(), 0, password.length());
            String secured = new BigInteger(1, digest.digest()).toString(16);
            return secured;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

采纳答案by nanofarad

but for now my job is to find the way to decrypt it

但现在我的工作是找到解密它的方法

Good luck. MD5 is a hash, which means a one-way, not necessarily bijective transformation, from input to output. MD5 is known to be weak but only for general collisions, and not for a chosen-hash attack. You can try every single possible input until you get the right hash(or a collision) but it is computationally expensive, and not a necessarily good idea. In addition, as a time-memory tradeoff, pre-generated rainbow tables may be used. They take long to generate, but have fast lookups. I will not provide a link them due to the controversy of using them, but you may obtain and acquire one freely, as long as you are within applicable laws in your jurisdiction. This process is still not a routine one, and isn't the best idea for a webapp or general application.

祝你好运。MD5 是一个散列,这意味着从输入到输出的单向变换,不一定是双射变换。众所周知,MD5 很弱,但仅适用于一般碰撞,而不适用于选择哈希攻击。您可以尝试每一个可能的输入,直到获得正确的散列(或冲突),但计算成本很高,而且不一定是个好主意。此外,作为时间-记忆权衡,可以使用预先生成的彩虹表。它们需要很长时间才能生成,但查找速度很快。由于使用它们的争议,我不会提供它们的链接,但只要您在您所在司法管辖区的适用法律范围内,您可以自由获取和获取它们。这个过程仍然不是常规过程,对于 webapp 或一般应用程序来说也不是最好的主意。

Have you looked into AES instead, which has a key, and encrypts, allowing decryption with that key?

你有没有研究过 AES,它有一个密钥,并进行加密,允许使用该密钥解密?

回答by Save

You can't reverse the MD5 algorithm, what you can do tho is to look for collisions and hope you'll find one. The most common way to crack a md5 hash are the rainbow tables, where you compare your hash with an enormous collection of precomputed hashes hoping to find a match.

你不能逆转 MD5 算法,你可以做的是寻找碰撞并希望你能找到一个。破解 md5 散列的最常见方法是彩虹表,您可以在其中将散列与希望找到匹配项的大量预计算散列集合进行比较。