iOS - 从指数+模数创建SecKeyRef [英] iOS - Creating SecKeyRef from exponent+modulus

查看:319
本文介绍了iOS - 从指数+模数创建SecKeyRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过将指数和模数作为私钥来解密iPhone上的RSA编码blob。在Java(使用javax.crypto)中,这可以通过以下代码轻松实现:

I would like to decrypt a RSA-encoded blob on iPhone, by having an exponent and modulus as private key. In Java (with javax.crypto), this could be easily achieved by code like this:

// 1) key
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(myModulus, myPublicExponent);
KeyFactory fact = KeyFactory.getInstance("RSA");
Key pubKey = fact.generatePublic(keySpec);

// 2) cypher
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec);

// 3) use cypher to decode my block to an output stream

但是使用iPhone安全API我不能创建SecKeyRef(密钥),除了生成一对或导入证书,我没有/想要。

But with the iPhone security API I can't create a SecKeyRef (key) other than by generating a pair or importing a certificate, which I don't have/want.

有没有办法手动创建一个具有模数+指数的密钥?如果是的话,你能告诉我一个怎样的线索吗?

Is there a way to create a key manually having a modulus + exponent? If so, can you give me a clue on how?

提前致谢

推荐答案

你的指数和模数如何编码?如果他们在 PKCS#12 blob中,您可以使用 SecPKCS12Import () SecIdentityCopyPrivateKey()以达到你想要的效果。

How are your exponent and modulus encoded? If they're in a PKCS#12 blob, you can use SecPKCS12Import() and SecIdentityCopyPrivateKey() to achieve what you want.

编辑:鉴于您有原始密钥,您可能有兴趣查看 - [SecKeyWrapper addPeerPublicKey:keyBits:] 示例由Apple提供

EDIT: Given that you have the raw keys, you might be interested in looking at the -[SecKeyWrapper addPeerPublicKey:keyBits:] example provided by Apple.

这篇关于iOS - 从指数+模数创建SecKeyRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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