ecc-exception-invalid-mac

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ecc-exception-invalid-mac

king13
This post has NOT been accepted by the mailing list yet.
We're using JDK 8,with bouncycastle 1.5. We have two PC. Each PC can encrypt and decrypt corretly. But if one PC encrypt, and the other one decrypt it, there is an exception thrown:

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)
Here is my decryption code:

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);`
I've searched a lot for invalid mac but no answers. Is it means ECC can only encrypt and decrypt on the same PC? Or is there anything wrong in it?