IPhone xcode从文件解密RSA

时间:2012-07-18 19:47:19

标签: iphone xcode file encryption rsa

使用安全框架中的苹果和常见的加密库我不想随机生成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); 

} 

是否可以使用此功能执行此操作,还是必须重写整个功能以适应我自己的私钥使用?

提前致谢!

1 个答案:

答案 0 :(得分:0)

我想出了如何通过输入文件路径并将文件导入项目来从文件中读取它。