【发布时间】:2014-04-08 17:39:59
【问题描述】:
我正在尝试使用以下方法加密 NSData:
- (NSData *) encryptWithData:(NSData *)content {
size_t plainLen = [content length];
void *plain = malloc(plainLen);
[content getBytes:plain
length:plainLen];
size_t cipherLen = 256;
void *cipher = malloc(cipherLen);
OSStatus returnCode = SecKeyEncrypt("PUBLIC KEY HERE", kSecPaddingPKCS1, plain,
plainLen, cipher, &cipherLen);
NSData *result = nil;
if (returnCode != 0) {
NSLog(@"SecKeyEncrypt fail. Error Code: %ld", returnCode);
}
else {
result = [NSData dataWithBytes:cipher
length:cipherLen];
}
free(plain);
free(cipher);
return result;
}
写在哪里 "PUBLIC KEY HERE" 我想加载一个我已经复制到我的捆绑包中的现有公钥。我该怎么做?
【问题讨论】:
-
你是如何复制到你的包的?
-
只是把它拖进xcode...
-
那是字符串的文件吗?
-
获取你拖拽的文件内容并作为key使用
标签: ios iphone encryption ios7 public-key-encryption