首页 > 解决方案 > 从 SHA 哈希到密码

问题描述

所以我已经编写了这段代码来转换为我的密码的哈希值,我现在想要获取哈希值并将其转换回字符串。怎么可能做到这一点?

package security;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashPassword {

    public static String hashPassword(String password) throws NoSuchAlgorithmException 
    {
        MessageDigest sha= MessageDigest.getInstance("SHA");
        sha.update(password.getBytes());
        byte [] b=sha.digest();
        StringBuffer sb= new StringBuffer();
        for(byte b1:b)
        {
            sb.append(Integer.toHexString(b1 & 0xff).toString());
        }

        return sb.toString();
    }
    public static void main(String[] args) 
    {
       String password="1234";
       System.out.println(password);
       try
       {
       System.out.println(hashPassword(password));
       }catch(NoSuchAlgorithmException e)
       {}
    }

}

标签: javastringhashpasswords

解决方案


你可以尝试用Rainbow table破解它


推荐阅读