在将系统转移到websphere上时,原来运行到好好的代码。突然就跑不起来了
查看日志文件后发现抛出了如下异常。
java 代码
- javax.crypto.BadPaddingException: Given final block not properly padded
- at com.ibm.crypto.provider.DESCipher.engineDoFinal(Unknown Source)
- at com.ibm.crypto.provider.DESCipher.engineDoFinal(Unknown Source)
- at javax.crypto.Cipher.doFinal(Unknown Source)
- at test.Decrypt.main(Decrypt.java:28)
跟踪输入,均没有问题。没辙,只能上网solo...
根据下面这篇所说,应该是IBM和SUN的随机数生成算法不一致造成的(http://www.ibm.com/developerworks/forums/message.jspa?messageID=3674765)
原代码:
java 代码
- KeyGenerator _generator = KeyGenerator.getInstance("DES");
- _generator.init(new SecureRandom(strKey.getBytes()));
- this.key = _generator.generateKey();
修改为:
java 代码
- KeyGenerator _generator = KeyGenerator.getInstance("DES");
- Security.addProvider(new sun.security.provider.Sun());
- SecureRandom sr = SecureRandom.getInstance("SHA1PRNG","SUN");
- sr.setSeed(strKey.getBytes());
- generator.init(sr);
- this.key = _generator.generateKey();
再把sun的jar包加到classpath即可。
记于此
分享到:
相关推荐
Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files java 8的权限文件
Java Cryptography with Examples 运用Jave软件包实现加密算法
Java Cryptography Extension (JCE) 无限强度权限策略文件 8 下载 Java Cryptography Extension 让应用能够使用更强大的标准算法。
java加解密无限制包,适用于JDK 8 ,JRE 8 。java能支持大部分的算法,但是受到出口限制,密钥长度不能满足需求。不过可以通过覆盖权限文件local_poblicy.jar和US_export_policy.jar取消相应限制。
OReilly - Java Cryptography.pdf
Java Cryptography
Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 包含版本6、7、8的权限文件
JCE是java加密扩展包,由于美国出口限制规定,JCE对部分国家是限制出口的,致使其加密长度有所缩减,例如,DES算法因受到军事出口限制,目前仅提供56位的密钥长度,而实际安全要求至少要128位。对于出口限制,SUN...
是一本不错Java Cryptography书,有代码
Beginning Cryptography with Java While cryptography can still be a controversial topic in the programming community, Java has weathered that storm and provides a rich set of APIs that allow you, the ...
Java - Introduction To Cryptography With Java Applets
Java Cryptography Extension(JCE)是一组包,它们提供用于加密、密钥生成和协商以及 Message Authentication Code(MAC)算法的框架和实现。它提供对对称、不对称、块和流密码的加密支持,它还支持安全流和密封的...
The Laws of Cryptography with Java Code.pdfThe Laws of Cryptography with Java Code.pdfThe Laws of Cryptography with Java Code.pdf
Beginning Cryptography With Java 且带有源代码,可以演示。
Series: Chapman & Hall CRC Cryptography and Network Security Series Publisher: Chapman and Hall/CRC City: Year: 2009 Edition: 1 Language: English Pages (biblio\tech): 287\287 ISBN: 1420075187, ...
jce的源码,很难的啊!里面有各种安全算法(rsa,md5,des,aes...)还有各种证书api(x.509,pkcs系列...),最近在搞网络安全,所搜集一些资料,希望对大家有帮助!
cryptography cryptography cryptography cryptography cryptography cryptography cryptography cryptography cryptography cryptography cryptography
Cryptography and Network Security.pdf 网络安全
ECC cryptography in java.