从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 下面添加自己的数据就可以了
引入之后运行打印
解决了,还有谁,哈哈