-->

MD5 algorithm Decryption in java [duplicate]

2020-06-23 06:00发布

问题:

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.

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;
    }

回答1:

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.

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



回答2:

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.