Last active
December 22, 2015 20:29
-
-
Save lkdocs/6526862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(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 base64EncodedString]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment