java.security.InvalidAlgorithmParameterException: IV must be 8 bytes long.

做AES、DES 等加密的时候会出现该类问题:

12-06 07:54:56.340  3515  3551 W System.err: java.security.InvalidAlgorithmParameterException: IV must be 8 bytes long.
12-06 07:54:56.341  3515  3551 W System.err: 	at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineInit(BaseBlockCipher.java:730)
12-06 07:54:56.341  3515  3551 W System.err: 	at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2664)
12-06 07:54:56.341  3515  3551 W System.err: 	at javax.crypto.Cipher.tryCombinations(Cipher.java:2575)
12-06 07:54:56.341  3515  3551 W System.err: 	at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2480)
12-06 07:54:56.341  3515  3551 W System.err: 	at javax.crypto.Cipher.chooseProvider(Cipher.java:567)
12-06 07:54:56.341  3515  3551 W System.err: 	at javax.crypto.Cipher.init(Cipher.java:975)
12-06 07:54:56.341  3515  3551 W System.err: 	at javax.crypto.Cipher.init(Cipher.java:910)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.core.BlockEncryptionHelper.getCipher(BlockEncryptionHelper.java:91)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.des.DESHelper.getCipher(DESHelper.java:13)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.des.DESEncryption.getCipher(DESEncryption.java:18)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.core.BlockEncryption.encryptFile(BlockEncryption.java:153)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.FileEncryption.encryptFiles(FileEncryption.java:145)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.FileEncryption.operation(FileEncryption.java:200)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.FileEncryption.-wrap0(Unknown Source:0)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.FileEncryption$EncryptionTask.doInBackground(FileEncryption.java:215)
12-06 07:54:56.342  3515  3551 W System.err: 	at com.shift.encrytion.FileEncryption$EncryptionTask.doInBackground(FileEncryption.java:213)
12-06 07:54:56.342  3515  3551 W System.err: 	at android.os.AsyncTask$2.call(AsyncTask.java:333)
12-06 07:54:56.342  3515  3551 W System.err: 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
12-06 07:54:56.342  3515  3551 W System.err: 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
12-06 07:54:56.342  3515  3551 W System.err: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
12-06 07:54:56.342  3515  3551 W System.err: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
12-06 07:54:56.342  3515  3551 W System.err: 	at java.lang.Thread.run(Thread.java:764)

问题很简单,key 的长度不对。

例如,AES 的密钥长度为128、192、256 位,也就是16 字节、24字节、32字节。

例如,DES 的密钥长度为64位(8个奇偶校验位),也就是8 个字节

 

详细看:

数据加密 ---- 总篇

 

 

 

 

 

 

你可能感兴趣的:(android,------,security)