Cipher c1 = Cipher.getInstance(Algorithm); ^^^^^^^^^ 最好指明Mode和Padding Cipher c1 = Cipher.getInstance("Blowfish/CBC/NoPadding");此外请注意你参数中传入的key的长度。 首先jdk1.4中SunJCE缺省的Blowfish keysize已经调整了。 --------------- SunJCE Default Blowfish Keysize Has Changed The SunJCE provider's default keysize for the Blowfish algorithm has changed from 56 bytes to 56 bits. 其次注意长度一定要是8的倍数,作为参数调用者是不一定传8倍数的长度的,所以接口开发者一定要自己作判断的。 ------------------ Blowfish: keysize must be a multiple of 8, and can only range from 32 to 448, inclusive
遇到同样问题,客户一定要使用md5加密后的字符串来作为Flowfish加密算法的密钥。md5加密后的字符串都是32字节字符串。报错: java.lang.SecurityException: Unsupported keysize or algorithm parameters at javax.crypto.Cipher.init(DashoA6275) at Crypt.encode(Crypt.java:30) at Crypt.main(Crypt.java:85)
^^^^^^^^^
最好指明Mode和Padding
Cipher c1 = Cipher.getInstance("Blowfish/CBC/NoPadding");此外请注意你参数中传入的key的长度。
首先jdk1.4中SunJCE缺省的Blowfish keysize已经调整了。
---------------
SunJCE Default Blowfish Keysize Has Changed
The SunJCE provider's default keysize for the Blowfish algorithm has changed from 56 bytes to 56 bits.
其次注意长度一定要是8的倍数,作为参数调用者是不一定传8倍数的长度的,所以接口开发者一定要自己作判断的。
------------------
Blowfish: keysize must be a multiple of 8, and can only range from 32 to 448, inclusive
还可以使用bouncycastle的包,那个做得要比sun的好得多。
http://www.bouncycastle.org/index.html
java.lang.SecurityException: Unsupported keysize or algorithm parameters
at javax.crypto.Cipher.init(DashoA6275)
at Crypt.encode(Crypt.java:30)
at Crypt.main(Crypt.java:85)