shiro: [Question] Can shiro 2.0 + use shiro 1 's hash Algorithm, such as "SHA-256" ?

Search before asking

  • I had searched in the issues and found no similar issues.

Question

I use shiro 2.0.0-alpha-2 with shiro 1 's hash Algorithm “SHA-256” , exception as below:

public static String str2SHA256(String str)
    {
        DefaultPasswordService passwordService = new DefaultPasswordService();
        passwordService.setHashService(new DefaultHashService()
        {
            {
                setDefaultAlgorithmName("SHA-256");
            }
        });
        String encryptedValue = passwordService.encryptPassword(str);
        return encryptedValue;
    }

exception:

Exception in thread "main" java.lang.UnsupportedOperationException: Shiro2CryptFormat can only format classes extending AbstractCryptHash.
	at org.apache.shiro.crypto.hash.format.Shiro2CryptFormat.format(Shiro2CryptFormat.java:107)
	at org.apache.shiro.authc.credential.DefaultPasswordService.encryptPassword(DefaultPasswordService.java:83)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Depending on the size of (and how much friction it would cause) your user base. You could reset passwords.

A more complex option would be to check if a user’s password has was stored in an older format, if so validate the hash. If it matches re-hash the password with a different algorithm and store it.

Shiro doesn’t provide password write APIs so you would need to write custom code for this.

NOTE: Someone could create a generic password service that would do most of the work UpgradableHashPasswordService, and then delegate the writes to an interface (that would be implemented by developers using Shiro)