org.apache.shiro.crypto.CryptoException: Unable to execute 'doFinal' with cipher instance

在整合 shiro的时候 每次登录和登出都出现这样的问题....

从两个红箭头 可以猜测出应该是rememberMe管理器的配置问题 ,而且异常部分也是rememberMe管理器里面配置的

 配置如下:

 

红箭头处的值有格式要求的 官文如下:

 

   你要么用base64生成字符串然后在decode,要么直接以0x开头的16进制窜.

 网上找到另个方法是在realm配置一下属性值 如下:

 

为啥好用呢 作用如下说明:

  Sets the indicator if this system's stored credential hash is Hex encoded or not. <p/> A value of true

 will cause this class to decode the system credential from Hex, a value of false will cause this class to

 decode the system credential from Base64. <p/> Unless overridden via this method, the default value

 is true for convenience - all of Shiro's Hash.toString() implementations return Hex encoded values by

 default, making this class's use with those implementations easier.

如果是true就使用realm所加密的hex 否则就使用base64 hex


shiro所有配置如下:

      <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- 配置securityManager -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="sessionManager" ref="sessionManager"></property>
        <property name="cacheManager" ref="cacheManager"></property>
        <property name="realm" ref="realm"></property>
    
        <!-- <property name="rememberMeManager" ref="rememberMeManager"></property> -->
    </bean>
    <!-- 配置cookies -->
    <!-- <bean id="rememberCookies" class="org.apache.shiro.web.servlet.SimpleCookie">
      <constructor-arg value="rememberMe"></constructor-arg>
      <property name="httpOnly" value="true"></property>
      <property name="maxAge" value="#{60*60*24}"></property>
    </bean>
    配置记住我管理器
    <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
        <property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode('6ZmI6I2j5Y+R5aSn5ZOlAA==')}"/>
        <property name="cookie" ref="rememberCookies"/>     
    </bean> -->
 <!-- 配置 realm  -->
     <bean id="realm" class="com.yy.ssm.realm.ShiroRealm">
         <property name="credentialsMatcher">
             <bean class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
                 <property name="hashAlgorithmName" value="MD5"></property>
                 <property name="hashIterations" value="1024"></property>
                 
                 <property name="storedCredentialsHexEncoded" value="true"></property>            
             </bean>
         </property>
     </bean>
    <bean id="sessionManager"
        class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
        <property name="sessionIdUrlRewritingEnabled" value="false"></property>
    </bean>
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"></property>
    </bean>
    
    <!-- 配置spring 自动调用init destroy方法 -->
    <bean id="lifeCycleProcesser" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean>
    <!-- 使用注解生效 -->
    <bean
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
        depends-on="lifeCycleProcesser" />
    <bean
        class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager" />
    </bean>
        <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
            <property name="securityManager" ref="securityManager"></property>
            <property name="loginUrl" value="login.jsp"></property>
            <property name="successUrl" value="/WEB-INF/views/index.jsp"></property>
        
            <property name="unauthorizedUrl" value="/WEB-INF/views/fail.jsp"></property>
            <property name="filterChainDefinitions">
                <value>
                    /login.jsp = anon
                    /css/*=anon
                    /login=anon
                    /logout=logout
                    /add_user=anon
                    /emp-list=anon
                    /register=anon
                    /register.jsp=anon
                    /images/*=anon
                    /jquery/*=anon
                    /static/**=anon
                    /**=authc
                </value>
            </property>
        </bean>
</beans>



ps:  public HashedCredentialsMatcher() {
        this.hashAlgorithm = null;
        this.hashSalted = false;
        this.hashIterations = 1;
        this.storedCredentialsHexEncoded = true; //false means Base64-encoded
    }

 默认为true 挺懵逼的,第一个方法要清除缓存,关闭浏览器,要么直接换一个就好了.


。在收到退出通知后,其他股东有 [设定期限] 的时间来行使优先收购权这个异常Shiro框架中的加密操作抛出的异常,表示在执行加密或解密操作时出。 b. 若其他股东放弃优先收购权或未在设定期限内行使,退出股东现问题。 这个异常的原因可能是以下之一: 1. 密钥不匹配:执行加密或解密可以向第三方出售其股权。 6. 争议解决: a. 任何因本协议操作时,可能使用了不正确的密钥。请确保在加密和解密过程中使用相同的密引起的争议,应通过友好协商解决。如协商不成,应提交至 [仲裁机构钥。 2. 算法不支持:执行加密或解密操作时,可能使用了不支持的加密算/仲裁委员会] 进行仲裁。 b. 仲裁裁决是终局的,对各方均法。请确保使用的加密算法是Java密码提供程序支持的。 3. 输入数据错误:执行加密或解密操作时,可能传入了无效的输入数据。请确保输入数据符合预期的格式和有约束力。 7. 其他条款: a. 本协议的任何修改或补充应经过要求。 4. 加密库配置问题:如果您在使用Shiro框架之前进行了一些自定义的加三方书面同意并签署。 b. 本协议对三方均具有约束力,在协议密库配置,可能会导致此异常。请检查您的加密库配置是否正确,并与Shiro框架的签署后生效。 本协议签署地点:[协议签署地点] 本协议签署日期:要求相匹配。 要解决此问题,您可以采取以下步骤: 1. 检查密钥:确保[协议签署日期] 甲方:________________ 乙方:________________ 丙方:________________ 请注意,这只是一个在加密和解密过程中使用相同的密钥,并且密钥是正确的。 2. 确认算法示例,具体的对赌协议内容应根据公司的具体情况进行调整和修改。建议在支持:查看您所使用的加密算法是否受Java密码提供程序支持。您可以查看Java密码起草和签署之前咨询法律专业人士以确保合规性。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值