dennisge
2017-12-19 20:41:47 +08:00
1. 这是原 java 的加密
a123456 => 79893503e8074330321974fa14dc44f8aa1b3df0
plainPassword = StringUtils.trim(plainPassword);
byte[] salt = Digests.generateSalt(SALT_SIZE); // af350c3413179ab4
byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), salt, HASH_INTERATIONS);
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
try {
MessageDigest digest = MessageDigest.getInstance(algorithm);
if (salt != null) {
digest.update(salt);
}
byte[] result = digest.digest(input);
for (int i = 1; i < iterations; i++) {
digest.reset();
result = digest.digest(result);
}
return result;
} catch (GeneralSecurityException e) {
throw Exceptions.unchecked(e);
}
}
2. node