【发布时间】:2013-01-11 17:04:33
【问题描述】:
我有以下代码来加密密码,但是当我尝试对其进行解码时,我没有得到预期的结果,这里是代码。
BASE64Encoder encoder = new BASE64Encoder();
String afterhex=toSHA1("mypassword".getBytes());
String encodedBytes = encoder.encodeBuffer(afterhex.getBytes());
public static String toSHA1(byte[] convertme) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return new String(md.digest(convertme));
}
例如,如果你尝试编码,jill 你应该得到LQBIF2TS0FSDYtGjaNmC2gl/klw=
任何恢复它的建议:)
【问题讨论】:
-
你不解密哈希。
-
散列!= 加密!
-
无法回答,因为您无法解密哈希。
-
SHA-1 不安全。你应该使用 bcrypt 或 PBKDFv2。
-
哈希是破解而不是“解密”,它们是使用 John The Ripper、彩虹表甚至在线免费服务等软件破解的。
标签: java security passwords password-protection password-encryption