Languages

Menu
Sites
Language
E_INVALID operation in aes_unwrap

       
Hi,
can anyone figure out the error here is my code

        ByteBuffer bufKey,bufKek;
        bufKek.Construct(16);
        bufKek.SetArray((byte *)"123456789012345",0,16);   //key used for wrapping
        bufKek.Flip();
        bufKey.Construct(16);
        bufKey.SetArray((byte *)"100100100100100",0,16); // key to be wrapped
        bufKey.Flip();
        AesCipher *asc=new AesCipher();
        asc->Construct("ECB/128/PKCS7PADDING",CIPHER_WRAP);        //wrap function 
        SecretKeyGenerator *kgen=new SecretKeyGenerator();
        kgen->Construct(bufKek);
        ISecretKey *ikey=kgen->GenerateKeyN();
        asc->SetKey(*ikey);
        ByteBuffer* enkey=asc->WrapN(*bufKey);
        AppLog("enkey is %s",enkey->GetPointer());

        AesCipher *asc1=new AesCipher();
        asc1->Construct("ECB/128/PKCS7PADDING",CIPHER_UNWRAP);   //un wrap function
        asc1->SetKey(*ikey);
        ByteBuffer *enkey1=asc->UnwrapN(*enkey);
        AppLog("enkey is %s",enkey1->GetPointer());

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

4 Replies
Alex Ashirov

Hi,

Please use

ByteBuffer *enkey1=asc1->UnwrapN(*enkey);

instead of

ByteBuffer *enkey1=asc->UnwrapN(*enkey);

Alex Ashirov

Also, please use ByteBuffer* enkey=asc->WrapN(bufKey);

instead of

ByteBuffer* enkey=asc->WrapN(*bufKey);

harish kumar kavali

hi,
its working

Alex Ashirov

Hi,

BTW, one more potential issue. You use the following:

bufKek.SetArray((byte *)"123456789012345",0,16);

and

bufKey.SetArray((byte *)"100100100100100",0,16);

This means that number of bytes to read from the given array is 16, but actual lengths of "123456789012345" and "100100100100100" equal to 15. IMHO, this also may cause some potential issues.