objective c - Can I use a key with 33-bytes in AES256 -


my friend wrote 2 methods aes256 objective-c. length of key kcckeysizeaes256+1 = 33 bytes

now need port 2 methods language such java, php, go. other languages don't accept 33-byte key

i can not change objective-c code because ios app online users.

please me port these 2 methods languages!!! (i hate friend)

objective-c methods:

nsdata * aes256encryptwith(nsdata *data, nsstring *key){     // 'key' should 32 bytes aes256, null-padded otherwise     char keyptr[kcckeysizeaes256+1]; // room terminator (unused)     bzero(keyptr, sizeof(keyptr)); // fill zeroes (for padding)      // fetch key data     [key getcstring:keyptr maxlength:sizeof(keyptr) encoding:nsutf8stringencoding];      nsuinteger datalength = [data length];      //see doc: block ciphers, output size less or     //equal input size plus size of 1 block.     //that's why need add size of 1 block here     size_t buffersize = datalength + kccblocksizeaes128;     void *buffer = malloc(buffersize);      size_t numbytesencrypted = 0;     cccryptorstatus cryptstatus = cccrypt(kccencrypt, kccalgorithmaes128, kccoptionpkcs7padding,                                           keyptr, kcckeysizeaes256,                                           null /* initialization vector (optional) */,                                           [data bytes], datalength, /* input */                                           buffer, buffersize, /* output */                                           &numbytesencrypted);     if (cryptstatus == kccsuccess) {         //the returned nsdata takes ownership of buffer , free on deallocation         return [nsdata datawithbytesnocopy:buffer length:numbytesencrypted];     }      free(buffer); //free buffer;     return nil; }  nsdata * aes256decryptwith(nsdata *data, nsstring *key){     // 'key' should 32 bytes aes256, null-padded otherwise     char keyptr[kcckeysizeaes256+1]; // room terminator (unused)     bzero(keyptr, sizeof(keyptr)); // fill zeroes (for padding)      // fetch key data     [key getcstring:keyptr maxlength:sizeof(keyptr) encoding:nsutf8stringencoding];      nsuinteger datalength = [data length];      //see doc: block ciphers, output size less or     //equal input size plus size of 1 block.     //that's why need add size of 1 block here     size_t buffersize = datalength + kccblocksizeaes128;     void *buffer = malloc(buffersize);      size_t numbytesdecrypted = 0;     cccryptorstatus cryptstatus = cccrypt(kccdecrypt, kccalgorithmaes128, kccoptionpkcs7padding,                                           keyptr, kcckeysizeaes256,                                           null /* initialization vector (optional) */,                                           [data bytes], datalength, /* input */                                           buffer, buffersize, /* output */                                           &numbytesdecrypted);      if (cryptstatus == kccsuccess) {         //the returned nsdata takes ownership of buffer , free on deallocation         return [nsdata datawithbytesnocopy:buffer length:numbytesdecrypted];     }      free(buffer); //free buffer;     return nil; } 

you should read comments in code... uses 32 bytes key. last byte string terminator... should use first 32 bytes 33byte key.

aes256 works 32bytes (which ist 256 bit)


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -