次の方法でエンコードされた文字列があります。この文字列を元の値にデコードする方法はありますか?ありがとう。
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;
}
SHA-256は暗号化(一方向)ハッシュ関数であるため、直接デコードする方法はありません。暗号化ハッシュ関数の目的は、元に戻せないことです。
できることの1つはブルートフォース戦略です。つまり、ハッシュされたものを推測し、同じ関数でハッシュして、一致するかどうかを確認します。ハッシュ化されたデータは非常に簡単に推測できない限り、長い時間がかかる可能性があります。
「パスワードのハッシュと暗号化の違い」という質問が興味深いかもしれません。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加