【发布时间】:2019-05-07 22:51:13
【问题描述】:
我们需要从 RSA 密钥中获取模数和指数。我使用以下方法创建了我的公钥。请让我知道我们如何从中获取模数和指数部分。我已经读过这个post。
NSData* tag = [@"com.x.x.x" dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* attributes =
@{ (id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA,
(id)kSecAttrKeySizeInBits: @1024,
(id)kSecPrivateKeyAttrs:
@{ (id)kSecAttrIsPermanent: @YES,
(id)kSecAttrApplicationTag: tag,
},
};
CFErrorRef error = NULL;
SecKeyRef privateKey = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes,
&error);
if (!privateKey) {
NSError *err = CFBridgingRelease(error);
// Handle the error. . .
}
SecKeyRef publicKey = SecKeyCopyPublicKey(privateKey);
// 现在我想要这个公钥的模数和指数
已编辑:- 我也将base64字符串发送到服务器,但我们面临着从base64字符串中找到公钥引用的相当大的问题。如果有人用c#做过,你也可以帮助我们
c#代码sn-p
const string pKey = "-----key-----"
byte[] publicKeyBytes = Convert.FromBase64String(pKey);
var stream = new MemoryStream(publicKeyBytes);
Asn1Object asn1Object = Asn1Object.FromStream(stream);
现在我们需要无法解析的公钥组件。任何帮助都会很棒
【问题讨论】:
-
我也将base64字符串发送到服务器,但是我们面临着从base64字符串中找到公钥引用的相当大的问题。如果有人用 c# 做过,你也可以帮助我们
标签: c# objective-c security rsa