/** 设定安全的密码,生成随机的salt并经过1024次 sha-1 hash */
  private void entryptPassword(User user) {
    byte[] salt = Digests.generateSalt(SALT_SIZE);
    user.setSalt(Encodes.encodeHex(salt));

    byte[] hashPassword = Digests.sha1(user.getPlainPassword().getBytes(), salt, HASH_INTERATIONS);
    user.setPassword(Encodes.encodeHex(hashPassword));
  }
Beispiel #2
0
 @Test
 public void hexEncode() {
   String input = "haha,i am a very long message";
   String result = Encodes.encodeHex(input.getBytes());
   assertEquals(input, new String(Encodes.decodeHex(result)));
 }