我们正在使用带有bouncycastle 1.5的JDK 8。 我们有两台电脑。每台PC都可以进行相应的加密和解密。但如果一台PC加密,另一台PC解密,则会抛出异常:
javax.crypto.BadPaddingException: Invalid MAC.
at org.bouncycastle.jcajce.provider.asymmetric.ec.IESCipher.engineDoFinal(Unknown Source)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at com.zhouxiang.cryption.bouncycastle.CryptionTest.main(CryptionTest.java:155)
这是我的解密代码:
File secKey = new File(ROOT_PATH+"pkcs8_key.key");
byte[] privateKeyB = readByte(secKey);
PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(privateKeyB);
KeyFactory privateFactory = KeyFactory.getInstance("ec",provider);
PrivateKey privateKey = privateFactory.generatePrivate(privateSpec);
Cipher privateCipher = Cipher.getInstance("ECIES/NONE/Nopadding", provider);
privateCipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] encryptedFromFile = readByte(new File(ROOT_PATH+"test/real/testout.dat"));
byte[] decrypted = privateCipher.doFinal(encryptedFromFile);
FileUtils.writeByteArrayToFile(new File(ROOT_PATH+"test/real/testout_de.txt"), decrypted);`
我搜索了很多无效的mac但没有答案。 是否意味着ECC只能在同一台PC上加密和解密?或者它有什么不对吗?