如何解密SHA-256加密字符串?我有一个使用以下方法编码的字符串,有没有办法将此字符串解码回原始值?谢谢。public synchronized String encode(String password)
throws NoSuchAlgorithmException, IOException {
String encodedPassword = null;
byte[] salt = base64ToByte(saltChars);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.reset();
digest.update(salt);
byte[] btPass = digest.digest(password.getBytes("UTF-8"));
for (int i = 0; i < ITERATION_COUNT; i++) {
digest.reset();
btPass = digest.digest(btPass);
}
encodedPassword = byteToBase64(btPass);
return encodedPassword;}private byte[] base64ToByte(String str) throws IOException {
BASE64Decoder decoder = new BASE64Decoder();
byte[] returnbyteArray = decoder.decodeBuffer(str);
return returnbyteArray;}private String byteToBase64(byte[] bt) {
BASE64Encoder endecoder = new BASE64Encoder();
String returnString = endecoder.encode(bt);
return returnString;}
3 回答

紫衣仙女
TA贡献1839条经验 获得超15个赞
SHA-256是一种加密(单向)哈希函数,因此没有直接的解码方法。加密哈希函数的全部目的是您无法撤消它。
你可以做的一件事是一个蛮力策略,你猜测什么是哈希值,然后用相同的函数哈希它,看它是否匹配。除非散列数据非常容易猜测,否则可能需要很长时间。

慕沐林林
TA贡献2016条经验 获得超9个赞
SHA *是一个哈希函数。它创建原始数据的表示(哈希)。此哈希永远不会用于重新创建原始数据。因此它不是加密。相反,可以在相同原始数据上的2个不同位置使用相同的散列函数来查看是否产生相同的散列。此方法通常用于密码验证。
添加回答
举报
0/150
提交
取消