【问题标题】:IPhone xcode RSA decryption from fileiPhone xcode RSA 从文件中解密
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多