如何在数据库中存储加密的密码?

pra*_*nna 3 java database encryption

我试图在JSP和Servlets的帮助下以加密的形式将密码存储到数据库中.我怎么能这样做?

Nic*_*oul 8

自编算法存在安全风险,维护起来很痛苦.
MD5 不安全.

使用jBcrypt提供的bcrypt算法(开源):

// Hash a password
String hashed = BCrypt.hashpw(password, BCrypt.gensalt());

// Check that an unencrypted password matches or not
if (BCrypt.checkpw(candidate, hashed))
    System.out.println("It matches");
else
    System.out.println("It does not match");
Run Code Online (Sandbox Code Playgroud)

如果您使用Maven,可以通过在pom.xml中插入以下依赖项来获取库(如果有更新的版本可以请告诉我):

<dependency>
    <groupId>de.svenkubiak</groupId>
    <artifactId>jBCrypt</artifactId>
    <version>0.4.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)