RSA加密公钥? [英] RSA Encryption public key?

查看:259
本文介绍了RSA加密公钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS中从Modulus和Exponent创建RSA加密公钥。
我已经从keychain创建公钥。

How can i create RSA encryption public key from 'Modulus' and 'Exponent' in iOS.? I have created public key from keychain. is it possible from string 'Modulus' and 'Exponent' values?

推荐答案

在这里查看这个答案

http://stackoverflow.com/a/10643894/584616

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

实施基本编码规则以启用导入的RSA键到iOS
KeyChain使用指数。代码定位iOS 5与ARC。

Implementation of Basic Encoding Rules to enable import of RSA keys to iOS KeyChain using exponent. Code targets iOS 5 with ARC.

假设您已经拥有一个来自
的模数和指数,一个RSA公钥作为名为pubKeyModData的变量的NSData,以及
pubKeyModData。然后下面的代码将创建一个包含RSA
公钥的NSData,然后你可以插入iOS或OS X Keychain。

Let's say you already have a modulus and exponent from an RSA public key as an NSData in variables named pubKeyModData and pubKeyModData. Then the following code will create an NSData containing that RSA public key, which you can then insert into the iOS or OS X Keychain.

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

这将允许您使用Apple CryptoExercise中SecKeyWrapper中的addPeerPublicKey:keyBits:例。或者,从底层API的角度来看,你可以使用SecItemAdd()。

This would allow you to store the key using the addPeerPublicKey:keyBits: method from SecKeyWrapper in the Apple CryptoExercise example. Or, from the perspective of the low-level API, you can use 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);

这篇关于RSA加密公钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆