RSAEncryptor 加密为空

来源:互联网 发布:windows图标缩小 编辑:程序博客网 时间:2024/06/05 03:24

从bundle中获取数据,明明把数据添加到项目中了,但就是不对。打印出来的都是空

//原始数据    NSString *originalString = @"这是一段将要使用'.der'文件加密的字符串!";        //使用.der和.p12中的公钥私钥加密解密    NSString *public_key_path = [[NSBundle mainBundle] pathForResource:@"public_key.der" ofType:nil];    NSString *private_key_path = [[NSBundle mainBundle] pathForResource:@"private_key.p12" ofType:nil];        NSString *encryptStr = [RSAEncryptor encryptString:originalString publicKeyWithContentsOfFile:public_key_path];    NSLog(@"加密前:%@", originalString);    NSLog(@"加密后:%@", encryptStr);    NSLog(@"解密后:%@", [RSAEncryptor decryptString:encryptStr privateKeyWithContentsOfFile:private_key_path password:@"55555"]);

调试过程中,在转码代码中打断点,然后到了断点处,在输出台

po [NSString stringWithContentsOfFile:public_key_path encoding:kCFStringEncodingUTF8 error:nil]发现打印null


当时添加是直接拖拽过去,后来发现没有真正加入到bundle中,需要在项目设置中,build phases-》copy bundle resources 下面添加自己的数据就可以了

引入之后运行打印

解决了,还有谁,哈哈

原创粉丝点击