1. 程式人生 > >DES對稱加密 併發引起的 java.lang.IllegalStateException: Cipher not initialized 異常

DES對稱加密 併發引起的 java.lang.IllegalStateException: Cipher not initialized 異常

專案在做高併發測試的時候,出現了異常如下,由於加密解密頻繁  

javax. crypto.Cipher 每次都要例項化,大量的例項化導致 Cipher 例項化失敗。 解決辦法:將已經例項化的Cipher物件,放在hashmap中,每次例項化的時候從MAP 獲取,不存在的時候再進行例項化,問題解決。
2018-07-07 10:45:39.543 DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
2018-07-07 10:45:39.544 DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [
[email protected]
] was not registered for synchronization because synchronization is not active 2018-07-07 10:45:39.544 DEBUG org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [[email protected]] will not be managed by Spring 2018-07-07 10:45:39.544 DEBUG com.jufengad.insurance.server.dao.InsuranceCategoryMapper.queryPageByparams - ==> Preparing: SELECT id, unique_code, parent_id, parent_code, category_name, description, category_key, category_level,pic_path, status, create_time, create_person from insurance_category where 1 = 1 order by category_level asc 2018-07-07 10:45:39.545 DEBUG com.jufengad.insurance.server.dao.InsuranceCategoryMapper.queryPageByparams - ==> Parameters: 七月 07, 2018 10:45:39 上午 org.apache.catalina.core.StandardWrapperValve invoke 嚴重: Servlet.service() for servlet [insurance_server_servlet] in context with path [/insurance-server] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cipher not initialized] with root cause java.lang.IllegalStateException: Cipher not initialized at javax.crypto.Cipher.checkCipherState(Cipher.java:1749) at javax.crypto.Cipher.doFinal(Cipher.java:2156) at com.jufengad.insurance.server.util.SecurityUtil.encrypt(SecurityUtil.java:88) at com.jufengad.insurance.server.util.SecurityUtil.getSecretKey(SecurityUtil.java:67) at com.jufengad.insurance.server.factory.impl.SimpleDtoFactory.getSecretKey(SimpleDtoFactory.java:54) at com.jufengad.insurance.server.factory.impl.SimpleDtoFactory.createResponse(SimpleDtoFactory.java:87) at com.jufengad.insurance.server.factory.impl.SimpleDtoFactory.createAdminResponse(SimpleDtoFactory.java:72) at com.jufengad.insurance.server.controller.product.ProductController.queryProductPage(ProductController.java:96) at com.jufengad.insurance.server.controller.product.ProductController$$FastClassBySpringCGLIB$$c19c8976.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:711) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) at com.jufengad.insurance.server.aop.ControllerLogAspect.doAroundMethod(ControllerLogAspect.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)