Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with javax.crypto.CipherOutputStream

2836446Jan 9 2015 — edited Jan 9 2015

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();

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2015
Added on Jan 9 2015
0 comments
674 views