0

I want to decrypt a very long base64 string of an encrypted JSON file, in which I'm provided with key and iv. And I'm not using the default PKCS7 padding instead I'm keeping the padding null in the encryption part. AES 256 encryption is of CBC mode.

With the help of "encrypt" dart package. I've tried decoding it, but the speed was very, very slow. But the solution I tried was natively configured respectively on Android & iOS, but It wasn't working on that long base64 encrypted string.


//This is some native code I wrote for iOS (Objective-C)


(NSString *)decrypt:(NSString *)text {
    NSString *result = 
      [text stringByTrimmingCharactersInSet:
      [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSData *decodedBase64Data = [[NSData alloc] 
      initWithBase64EncodedString:result options:0]; //Decode Base64
    NSData *decodedAESData = [decodedBase64Data 
      AES256DecryptedDataWithKey:rd_key iv:rd_iv]; //Decode AES 256
    result = [[NSString alloc] initWithData:decodedAESData 
    encoding:NSUTF8StringEncoding];
    return result;
}

Is there any faster or a native solution to this problem? as I'm not able to decrypt the whole base64 encrypted string.

Base64 encypted String = "...2Btn9j6DjFOFgN2gUgVWv8!2FE94hmTZqge6wFMWCMBwRKu!
2BhaUSbip!2Brxa0tF5JqzVukbz4cbWZE6NGNgrA5BAeNHh3RVFBuoOG!2F!2Fiw!2BmsUob4W5ab9
P0lnHhPU9hk2qlfbj1ydS6m9OYYFwl!2F1QXAJ2I6lVZ81HYzeupP42!2BxqIx3zyURHZwQsCuOZ!
2BYits!2FqBC!2BSvAfiCUCeEOSqaAaLjbxXNAaIrtHRh3B9boAPESTxTKzUSC!2Bhpa72xk7
Dby8cl0MlflPAc9P2ihO3SD5GNVm9HWIjMga41OUvw1xMsgqqe5G5YnsNOom57cnLkj
JJhxsnfgnqaKxpAK0fdsov3f6!2FRDAVrSQledg4PWpQpNw9PCmIpzvk6!2wCbHck8
OlJm!2Br7NI9FNTfhJ2YceXohNkAZPkWW!2F2j9egRHNhbZNxGZoFnVE!2FgP1Zyqd6R
8Ma3b!2BhqCCWT4ZoSXXals26jVtkCMU5NA!2FWfxi6LbbsukyS9ViNj3gP8eCUH1!2Fbq
nLWXRfN03yqDcjM9tTFvSjorbqvf0sI0Go7crwJGaX7ODB4C!2FWcZ8plUTmqTZI!2BNUE
QKlxvGd24Vf!2B!2Br5ZvzvcM3Ew3CEw4JM1IZb30mqFEgFAt8dv08fj!2FRsQYt8PfK!2
r0ucWIAXVNz0ZySX6lgSza0ZHMSot!2BpUzt0Ru8vUuALL1g5xoEgh1l4yyjs2Dmxz4mJ4
0PNxdvye1FIjY!...";

Decrypted data should be like this!

beingRD
  • 1
  • 3
  • Welcome to SO. It seems that you are using a strange library. Try this [How to encrypt with AES 256 CBC in Objective C](https://stackoverflow.com/q/45832991/1820553) – kelalaka Aug 21 '19 at 09:48
  • Try and use streams / online decoding & decryption rather than doing everything in one go, in two different steps. CPU's are fast, memory is not that fast and using spurious memory should be avoided. – Maarten Bodewes Aug 21 '19 at 11:23
  • @MaartenBodewes I don't understand what you meant by that. Do check the image I recently attached maybe that can be of some help to understand the issue in hand. – beingRD Aug 22 '19 at 07:18
  • Streams are a programming concept you can look up, online encryption / decryption is similar in that you split the input into chunks and try and decrypt those piecemeal rather than everything in one go. – Maarten Bodewes Aug 22 '19 at 11:22
  • `package:webcrypto` offers streaming decryption, see https://pub.dev/packages/webcrypto – jonasfj Aug 24 '22 at 16:06

0 Answers0