从模数和初始化公钥使用 OpenSSL 的指数
尝试在给定 API 模数和指数的情况下生成 RSA 公钥。我在 iOS 4.2 上使用 OpenSSL。
手动生成公钥是一个选项(见下文),但是我不确定如何在模数中包含指数逻辑
-----BEGIN PUBLIC KEY-----
Modulus from API
-----END PUBLIC KEY-----
基于@James 评论,我可以编写公共 pem 但得到空白私钥。这是我的代码:
char szModulus = "1162" ;
char *szExp = "827655" ;
RSA* rsa = RSA_new();
int ret = BN_hex2bn(&rsa->n,szModulus) ;
ret = BN_hex2bn(&rsa->d,szExp) ;
FILE *fp = fopen("/Users/ysi/Desktop/privateKey.pem", "wb");
PEM_write_RSAPrivateKey(fp, rsa, NULL, NULL, 0, 0, NULL);
Trying to generate an RSA Public Key given an APIs modulus and exponent. I'm using OpenSSL on iOS 4.2.
Generating the public key manually is an option (see below) however i'm not sure how to include the exponent logic in the modulus
-----BEGIN PUBLIC KEY-----
Modulus from API
-----END PUBLIC KEY-----
Based on @James comments, I am able to write public pem but getting blank private key. Here is my code:
char szModulus = "1162" ;
char *szExp = "827655" ;
RSA* rsa = RSA_new();
int ret = BN_hex2bn(&rsa->n,szModulus) ;
ret = BN_hex2bn(&rsa->d,szExp) ;
FILE *fp = fopen("/Users/ysi/Desktop/privateKey.pem", "wb");
PEM_write_RSAPrivateKey(fp, rsa, NULL, NULL, 0, 0, NULL);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,请确保您已链接 OpenSSL 库(此处的说明 http://code. google.com/p/ios-static-libraries/)
链接后,您将可以访问多个 BIGNUM 转换器。我使用 BN_hex2bn 方法将模数转换为十六进制,将十六进制字符串保存为“指数”
然后创建 BIGNUM 结构并使用 RSA_public_encrypt 加密
祝你好运!
To do this make sure you have the OpenSSL library linked (instructions here http://code.google.com/p/ios-static-libraries/)
Once linked you'll have access to several BIGNUM converters. I turned the modulus into hex using the BN_hex2bn method saving the hex string into 'exponent'
Then create the BIGNUM struct and encrypt using RSA_public_encrypt
Good Luck!