简体   繁体   English

在iOS中使用已知模数和指数密钥的RSA算法加密NSString

[英]Encrypt NSString with RSA Algorithm with known modulus and exponent keys in iOS

In iOS app, I need to encrypt NSString with RSA Algorithm, I have known public modulus and exponent key.On Android side they have used bouncy castle ApI for RSA Encryption.Can some one help me how to encrypt how can I encrypt NSString with these Public Modulus and Exponent key as could generate similar encryption as in Android.I have looked on many source code available but could not generate the correct encryption.Any help would be highly appreciated. 在iOS应用中,我需要使用RSA算法对NSString进行加密,我知道公共模数和指数密钥。在Android方面,他们使用有弹性的城堡ApI进行RSA加密。有人可以帮助我如何进行加密,如何使用这些对NSString进行加密Public Modulus和Exponent密钥可以生成与Android中类似的加密。我查看了许多可用的源代码,但无法生成正确的加密。我们将不胜感激。 Modulus key That I have is "117130940722358865944076735715016871148960803304334901248996815419815052552875336322790410991392433604701394608500231884113911915168625416296669114728862690539451024021812353340986348428958506523689933432584403548435474622224828221548841371083486321081622447517054022904372023020885356296462823306439795173749" Exponent is "65537" Please help me to encrypt NSString with RSA Encryption. 我拥有的模数密钥是“ 11713094072235886594407673571501687114896080330433490124899681541981505255287533632279041099139260460470139460850023188411391191516862541629666911472886269053945102402181235334098634842895850652368993368258343440440547547462222822154884137108348632795637375842394735382

You can use openSSL for this 您可以为此使用openSSL

https://www.openssl.org/docs/man1.1.0/crypto/RSA_public_encrypt.html https://www.openssl.org/docs/man1.1.0/crypto/RSA_public_encrypt.html

#include <openssl/rsa.h>
 int RSA_public_encrypt(int flen, unsigned char *from,
    unsigned char *to, RSA *rsa, int padding);
 int RSA_private_decrypt(int flen, unsigned char *from,
     unsigned char *to, RSA *rsa, int padding);

Be aware of export compliance though Using SSL in an iPhone App - Export Compliance 通过在iPhone应用程序中使用SSL来了解出口合规性-出口合规性

You may be better trying to get the Common Crypto equivalent to work 您可能会更好地尝试使Common Crypto等效工作

Being in iOS, you probably need to work without extra libs like OpenSSL. 在iOS中,您可能需要没有像OpenSSL这样的额外库。 But to do so, you must have some kind of "big numbers" library. 但要这样做,您必须具有某种“大数字”库。 I am not using iOS, but a search gives this mention of "huge numbers" library, discussed here: Store and perform operations with huge numbers in iOS With this library, you need only RSA formulas. 我没有使用iOS,但是搜索中提到了“巨大数字”库,在这里进行了讨论: 在iOS中存储和执行具有巨大数字的操作使用此库,您仅需要RSA公式。 Fast search gives this article http://www.linuxjournal.com/article/6695 , you don't need to all of it, just scroll down to mention of ModExp - this is an operation you need to encrypt a message when you have key and modulus available. 快速搜索给出了本文http://www.linuxjournal.com/article/6695 ,您不需要全部,只需向下滚动以提及ModExp-这是您需要对消息进行加密的操作可用的密钥和模数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM