无法将NSString/NSData
转换为SecKeyRef
。
我用Google搜索了,但找不到合适的答案。
我需要使用公钥进行RSA加密。我从服务器获取公钥作为NSData。需要将转换作为参数传递给下面的代码。
- (NSString *)encryptRSA:(NSString *)plainTextString key:(SecKeyRef)publicKey {
size_t cipherBufferSize = SecKeyGetBlockSize(publicKey);
uint8_t *cipherBuffer = malloc(cipherBufferSize);
uint8_t *nonce = (uint8_t *)[plainTextString UTF8String];
SecKeyEncrypt(publicKey,
kSecPaddingOAEP,
nonce,
strlen( (char*)nonce ),
&cipherBuffer[0],
&cipherBufferSize);
NSData *encryptedData = [NSData dataWithBytes:cipherBuffer length:cipherBufferSize];
//return [encryptedData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
return [DJUtility base64forData:encryptedData];
}