【发布时间】:2012-07-18 19:47:19
【问题描述】:
使用苹果内置的安全框架和通用加密库,我不想随机生成 RSA 密钥,但我想将包含我的特殊私钥的文件硬编码到以下函数中:
在此处找到以下代码,但我想对其进行修改以完成上述操作:Iphone - How to encrypt NSData with public key and decrypt with private key?
- (void)decryptWithPrivateKey:(uint8_t *)cipherBuffer plainBuffer:(uint8_t *)plainBuffer
{
OSStatus status = noErr;
size_t cipherBufferSize = strlen((char *)cipherBuffer);
NSLog(@"decryptWithPrivateKey: length of buffer: %lu", BUFFER_SIZE);
NSLog(@"decryptWithPrivateKey: length of input: %lu", cipherBufferSize);
// DECRYPTION
size_t plainBufferSize = BUFFER_SIZE;
// Error handling
status = SecKeyDecrypt([self getPrivateKeyRef],
PADDING,
&cipherBuffer[0],
cipherBufferSize,
&plainBuffer[0],
&plainBufferSize
);
NSLog(@"decryption result code: %ld (size: %lu)", status, plainBufferSize);
NSLog(@"FINAL decrypted text: %s", plainBuffer);
}
是否可以使用此函数来完成,还是我必须重写整个函数以适应我自己的私钥使用?
提前致谢!
【问题讨论】:
标签: iphone xcode file encryption rsa