org.springside.modules.security.utils.Digests Java Examples

The following examples show how to use org.springside.modules.security.utils.Digests. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountService.java    From spring-boot-quickstart with Apache License 2.0 5 votes vote down vote up
/**
 * 设定安全的密码,生成随机的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));
}
 
Example #2
Source File: AccountService.java    From Mario with Apache License 2.0 5 votes vote down vote up
/**
 * 设定安全的密码,生成随机的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));
}
 
Example #3
Source File: GeneratePasswordTest.java    From Mario with Apache License 2.0 5 votes vote down vote up
/**
 * 测试生成password
 * 规则如下,
 * 1、获得随机的SALT_SIZE位byte[]字符,然后使用decodeHex获取salt字符,保存salt字符到数据库中,
 * 2、使用sha1算法,生成密码,调用enecodeHex,生成最后的password,保存password到数据库中
 */
@Test
public void testSalt() {
    byte[] salt = Encodes.decodeHex(code);

    byte[] hashPassword = Digests.sha1(password.getBytes(), salt, HASH_INTERATIONS);
    String actualPassword = Encodes.encodeHex(hashPassword);

    Assert.assertEquals(exceptPassword, actualPassword);

}
 
Example #4
Source File: UserService.java    From dubai with MIT License 5 votes vote down vote up
/**
 * 设定安全的密码,生成随机的salt并经过1024次 sha-1 hash
 */
void entryptPassword(User user, String plainPassword) {
    byte[] salt = Digests.generateSalt(SALT_SIZE);
    user.setSalt(Encodes.encodeHex(salt));

    byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), salt, HASH_INTERATIONS);
    user.setPassword(Encodes.encodeHex(hashPassword));
}
 
Example #5
Source File: UserService.java    From dubai with MIT License 4 votes vote down vote up
void generateActKey(User user) {
    user.setActKey(Encodes.encodeHex(Digests.sha1((user.getLoginName() + System.currentTimeMillis()).getBytes())));
    user.setActKeyGenDate(Calendar.getInstance().getTime());
    user.setActDate(user.getActKeyGenDate());
}