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!

AES padding issue

843811May 18 2007 — edited May 19 2007
I searched this forum and couldn't find anything that explained my exact situation so here it is....

I am trying to decrypt some data and I end up with 0 bytes padded at the end. Any idea what I am doing wrong? Here is my decrypt() method:
    protected final byte[] decrypt( final byte[] key, final byte[] value )
        throws Exception {

        SecretKeySpec skeySpec = new SecretKeySpec( key, "AES" );
        Cipher cipher = Cipher.getInstance( "AES/ECB/NoPadding" );
        cipher.init( Cipher.DECRYPT_MODE, skeySpec );

        byte[] buffer = new byte[cipher.getOutputSize( value.length )];
        int size = cipher.update( value, 0, value.length, buffer, 0 );
        size += cipher.doFinal( buffer, size );

        byte[] trimmed = new byte[size];
        System.arraycopy( buffer, 0, trimmed, 0, size );

        return trimmed;
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2007
Added on May 18 2007
6 comments
232 views