Forum Stats

  • 3,840,396 Users
  • 2,262,599 Discussions
  • 7,901,263 Comments

Discussions

Problem with javax.crypto.CipherOutputStream

2836446
2836446 Member Posts: 1
edited Jan 9, 2015 10:38AM in Cryptography

Hi, i have a problem with using the javax.crypto.CipherOutputStream-Class in AEAD mode.

I try to encrypt a file andthat seems to work properly.

But if i try to decrypt this file, the file will be created but the size is 0 byte.

I don't know if it's a Bug in the CipherOutputStream-class or have I misunderstood something?

ciper is in AEAD mode...

but if i try to encrypt and to decrypt data without using CipherInputStream and CipherOutputStream it will be works fine...

cipher = Cipher.getInstance("AES/GCM/PKCS5Padding");
cipher.init(cipherMode, secret, new GCMParameterSpec(128, nonce));
....
....

CipherOutputStream  cos = new CipherOutputStream(encryptedOutStream, cipher);         int blockSize = cipher.getBlockSize();         while ((n = inputStream.read(byteBuffer)) != -1) {             cos.write(byteBuffer, 0, n);         }         cipher.updateAAD(ad);         cos.close();         encryptedOutStream.close();         inputStream.close();
This discussion has been closed.