I create new users who can log into my Java EE application using Jasypt to hash the password: I use SHA-256, an 8 bytes salt, 1000 iterations and get an 80-character hexadecimal hash in the database. This is working. Here is the code:
ConfigurablePasswordEncryptor passwordEncryptor = new ConfigurablePasswordEncryptor();
SimpleDigesterConfig config = new SimpleDigesterConfig();
config.setAlgorithm( "SHA-256" );
config.setIterations( 1000 );
config.setSaltSizeBytes( 8 );
passwordEncryptor.setConfig( config );
passwordEncryptor.setPlainDigest( false );
passwordEncryptor.setStringOutputType( "hexadecimal" );
String hashedPassword = passwordEncryptor.encryptPassword( password );
Then I store it in the DB.
Now, in my DataSource Realm, I'm trying to tell Tomcat what I am doing like this:
<Realm
className="org.apache.catalina.realm.DataSourceRealm"
name="monRealm"
dataSourceName="jdbc/postgres"
localDataSource="true"
userTable="users" userNameCol="login" userCredCol="password"
userRoleTable="user_roles" roleNameCol="role_name"
debug="99">
<CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler"
algorithm="SHA-256"
iterations="1000"
keyLength="256"
saltLength="8"
/>
</Realm>
In my opinion, this is the same thing. And the Realm should check the password just fine.
But I never manage to log in with the login/password I have created. It works without the hash part, so this is really the way I hash the password that is wrong. But I can't see where I missed something.
Thanks in advance for you help!