Advertisement
Guest User

AES_128_ECB_PKCS5Padding_Decrypt

a guest
Sep 10th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. char * AES_128_ECB_PKCS5Padding_Decrypt(const char *in, const uint8_t* key)
  2. {
  3.     size_t inputLength = 0;
  4.     uint8_t *inputDesBase64=b64_decode_ex(in,strlen(in), &inputLength);
  5. //    const size_t inputLength= (strlen(in) / 4) * 3;
  6.     uint8_t *out=malloc(inputLength);
  7.     memset(out,0,inputLength);
  8.     size_t count=inputLength/16;
  9.     if (count<=0)
  10.     {
  11.         count=1;
  12.     }
  13.     size_t i;
  14.     for ( i = 0; i < count; ++i) {
  15.         AES128_ECB_decrypt(inputDesBase64+i*16,key,out+i*16);
  16.     }
  17.  
  18.  
  19.     // remove padding
  20.     int index = findPaddingIndex(out, inputLength);
  21.     if(index==NULL)
  22.     {
  23.         return (char*)out;
  24.     }
  25.     if(index < inputLength){//  if (index>strlen)  will crash.
  26.         memset(out+index, '\0', inputLength-index);
  27.     }
  28.  
  29.     free(inputDesBase64);
  30.     return (char *) out;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement