0

Using the apple built in Security framework and common crypto libraries I do not want to randomly generate RSA keys but I want to hardcode the file containing my special private key into the following function:

Code below was found here but I want to modify it to accomplish the above: 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); 

} 

Is it possible to do it with this function or do I have to rewrite the whole function to accomidate for my own private key use?

Thanks in advance!

Community
  • 1
  • 1
user1431272
  • 93
  • 2
  • 13

1 Answers1

0

I figured out how to read this from a file by inputing the file path and importing the files to the project.

user1431272
  • 93
  • 2
  • 13