1. 程式人生 > >Shiro異常java.lang.IllegalArgumentException: Odd number of characters的解決方案

Shiro異常java.lang.IllegalArgumentException: Odd number of characters的解決方案

java.lang.IllegalArgumentException: Odd number of characters.
    at org.apache.shiro.codec.Hex.decode(Hex.java:128) ~[shiro-core-1.3.2.jar:1.3.2]
    at org.apache.shiro.codec.Hex.decode(Hex.java:107) ~[shiro-core-1.3.2.jar:1.3.2]
    at org.apache.shiro.codec.Hex.decode(Hex.java:95) ~[shiro-core-1.3.2.jar:1.3.2]
    at org.apache.shiro.authc.credential.HashedCredentialsMatcher.getCredentials(HashedCredentialsMatcher.java:353) ~[shiro-core-1.3.2.jar:1.3.2]
    at org.apache.shiro.authc.credential.HashedCredentialsMatcher.doCredentialsMatch(HashedCredentialsMatcher.java:380) ~[shiro-core-1.3.2.jar:1.3.2]
    at org.apache.shiro.realm.AuthenticatingRealm.assertCredentialsMatch(AuthenticatingRealm.java:597) ~[shiro-core-1.3.2.jar:1.3.2]

原因很簡單,就是你從資料庫中查出來的資料不是密文的,
在realm檔案中,身份驗證最後一句話一般這麼寫,這裡傳入的第二個引數password必須是密文的,是你使用的加密方式的密文 , 比如 mD5 ,sha256等

return new SimpleAuthenticationInfo(token.getPrincipal(), password, salt, getName());