IPhone / Objective-c RSA Encryption

I am looking for and analyzing answers to the question of how to make simple RSA encryption using Cbjective-C on iPhone. The main problem is that I was provided with Exponent and Modulus as an object NSData, and I then need to convert them to an object SecKeyRefin order to perform RSA encryption.

Does anyone know how to do this or are there some helpful hints?

Many thanks!

+3
source share
2 answers

In my project, I used OpenSSL. and import keys and encrypt using this library instead of iPhone.

+2
source

GitHub. API, Apple, Keychain OpenSSL. ( , OpenSSL ).

https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS

-BasicEncodingRules-

, RSA iOS KeyChain . iOS 5 ARC.

, RSA NSData pubKeyModData pubKeyModData. NSData, RSA , iOS Keychain OS X.

NSMutableArray *testArray = [[NSMutableArray alloc] init];
[testArray addObject:pubKeyModData];
[testArray addObject:pubKeyExpData];
NSData *testPubKey = [testArray berData];

addPeerPublicKey: keyBits: SecKeyWrapper Apple CryptoExercise. , API, SecItemAdd().

NSString * peerName = @"Test Public Key";

NSData * peerTag = 
   [[NSData alloc] 
       initWithBytes:(const void *)[peerName UTF8String] 
       length:[peerName length]];

NSMutableDictionary * peerPublicKeyAttr = [[NSMutableDictionary alloc] init];

[peerPublicKeyAttr 
   setObject:(__bridge id)kSecClassKey 
   forKey:(__bridge id)kSecClass];
[peerPublicKeyAttr 
   setObject:(__bridge id)kSecAttrKeyTypeRSA 
   forKey:(__bridge id)kSecAttrKeyType];
[peerPublicKeyAttr 
   setObject:peerTag 
   forKey:(__bridge id)kSecAttrApplicationTag];
[peerPublicKeyAttr 
   setObject:testPubKey 
   forKey:(__bridge id)kSecValueData];
[peerPublicKeyAttr 
   setObject:[NSNumber numberWithBool:YES] 
   forKey:(__bridge id)kSecReturnPersistentRef];

sanityCheck = SecItemAdd((__bridge CFDictionaryRef) peerPublicKeyAttr, (CFTypeRef *)&persistPeer);
0

Source: https://habr.com/ru/post/1734313/


All Articles