我想的NSData以下方法进行加密:RSA加密使用现有的公共密钥
- (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;
}
,里面写到“公用钥匙HERE”我要加载现有的公共键我已经复制到我的包。我怎样才能做到这一点?
你怎么复制到你的包吗? – Rajesh
只是把它拖入xcode ... – davidOhara
这是一个字符串的文件吗? – Rajesh