RSA使用公钥加密 [英] RSA Encryption using public key

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

问题描述

我正在写iOS应用程序。服务器发送RSA公钥给应用程序。现在应用程序必须使用RSA算法加密一些信息



请给我一些参考。
感谢

解决方案

iOS对RSA没有特殊的API,但有一些关于证书的API。您可以使用这些API通过RSA对数据进行加密。



首先,您必须使用openssl来生成您的RSA私钥和公钥。最重要的是公钥必须签名。这是生成密钥的指令。

  openssl req -x509 -out public_key.der -outform der -new -newkey rsa :1024 -keyout private_key.pem -days 3650 

但是,如果您已经有私钥(。 pem文件),您可以按照以下说明操作:

  openssl req -new -out cert.csr -key private_key.pem 
openssl x509 -req -in cert.csr -out public_key.der -outform der -signkey private_key.pem -days 3650

您可以通过在xcode中打开来查看 public_key.der



当您获得正确的 public_key .der 文件,您可以查看RSA.h和RSA.m 这里。很抱歉,我没有时间再次用英文重写这篇文章。


I am writing iOS Application. Server sends RSA public key to application. Now application has to encrypt some information using RSA algorithm

Kindly provide me some reference. Thanks

解决方案

iOS has no special API for RSA, but there are some APIs about Certificate. You can use these APIs to encrypt your data by RSA.

First, you must use openssl to generate your RSA private key and public key. The most important thing is that the public key must be signed. Here is a instruction to generate the keys.

openssl req -x509 -out public_key.der -outform der -new -newkey rsa:1024 -keyout private_key.pem -days 3650

However, if you already has a private key(.pem file), you can follow the instructions:

openssl req -new -out cert.csr -key private_key.pem
openssl x509 -req -in cert.csr -out public_key.der -outform der -signkey private_key.pem -days 3650

You can check the public_key.der by opening it in xcode.

When you get the correct public_key.der file, you can view the RSA.h and RSA.m here. I'm sorry that I have no time to rewrite this post by English again.

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

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