首页 > 解决方案 > 为什么 decrytedText 为 NULL?

问题描述

我的应用从 GET 请求中接收加密数据。我在解密数据时遇到问题。我正在使用跨平台的 CryptLib 库CryptLib。遵循 CryptLib.m 中的文档,但似乎没有任何效果。如果有人对 CryptLib 有所了解,将不胜感激,请在下面查看我的代码。

代码

[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
  ^(NSData * _Nullable encryptedData,
    NSURLResponse * _Nullable response,
    NSError * _Nullable error) {
      //has data
      NSString *jsonData = [[NSString alloc] initWithData:encryptedData encoding:NSUTF8StringEncoding];
      NSLog(@"Data received: %@", jsonData);


      NSString *key = @"3HS5UtP7hEc5Jsqg7P4KDQEH2y95v92Z";
      NSString *iv = @"ZkjH27Rh63RQtH8y";

    //Decrypted data is NULL!
      encryptedData = [[StringEncryption alloc] decrypt:encryptedData  key:key iv:iv];
      NSString * decryptedText = [[NSString alloc] initWithData:encryptedData encoding:NSUTF8StringEncoding];
      NSLog(@"decrypted data:: %@", decryptedText); //print the decrypted text


  }] resume];

标签: iosobjective-ccryptlib

解决方案


推荐阅读