使用Cipher进行解密时报错
2016-03-14 18:02
387 查看
String result="一段加密的字符串"; byte[] textBytes = Base64.decodeBase64(result); AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes); SecretKeySpec newKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = null; cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, newKey, ivSpec); String string2 = new String(cipher.doFinal(textBytes), "UTF-8");//机密完的字符串
今天对接一个客户的接口,使用的解密方式之前没遇到过,用Cipher这个进行加解密,几行代码中就碰到了两次报错,而且是比较少见的,百度上面好不容易才搜到两个,特此记录仪一下。
1、如果报错:java.security.InvalidKeyException: Illegal key size
请更换 JDK路径\jre\lib\security 文件底下的local_policy.jar和US_export_policy.jar
详情请参考:http://bbs.csdn.net/topics/340263760
2、如果报错:java.lang.SecurityException: Cannot set up certs for trusted CAs
请更换 jce.jar 包 或者使用更高版本的JDK
详情请参考:http://blog.csdn.net/tomy_xu_1981/article/details/539323
相关文章推荐
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- MyEclipse关联Oracle数据库
- Mysql性能测试诊断
- 4.PopupWindow
- 相机标定:关于本质矩阵和基本矩阵
- android:padding和android:margin的区别
- 编辑ISPF主菜单ISR@PRIM
- Android Studio中application module,library module,java module的区别
- Hibernate注解属性allocationSize
- Web页面之间参数传递方法
- EIO框架测试Demo
- JQuery:选择器、动画、AJAX请求
- Java虚拟机工作原理详解 ( 二 )
- 文档的作用和分类
- 如何导出项目pom中引用的mavenjar包
- Http协议
- SCCM2012R2之四发现方法
- struts2 实现过程和xml配置
- VS2013 Error LNK2019 about extern C
- 白色情人节临摹社交应用登录框