Ios-rsa and decryption sharing

Source: Internet
Author: User

This article reprinted to http://www.cocoachina.com/bbs/read.php?tid=235527Search a lot of information, did not find the right RSA method, a lot of people are asking this question, solved the comrades do not share, so let me share it, good to a praise!! Not good, do not spray, everyone modified to get up on the good ...
Can not only take, do not contribute ...
This project client does not use OpenSSL to generate the de, directly using this library to generate PublicKey and Privatekey.
The program was modified by the Https://github.com/kuapay/iOS-Certificate--Key--and-Trust-Sample-Project project, This item is encrypted when more than 100 of the length can not be encrypted (modified compatible many many bytes)!! Decryption because the project does not need, did not do the Shard decompression, only support more than 100 bytes (project urgency, no time to change), we can modify this method! I'll share it after writing.
-(NSString *) Decrypt: (NSString *) ciphertext
Key: (NSString *) key
Error: (Nserror *) error!!

Applicable environment:
1. The iOS application automatically generates the public key, the private key, and saves it. It's all going to be sandbox extraction.
2. The server public key generates the SECKEYREF format in der format for transmission to the server.
3, encryption has been Base64, after decryption has been base64.
Encryption:
rsacryptor *r = [Rsacryptor shareinstance];

Long randomdata = random ();

NSString *pubstr = [NSString stringwithformat:@ "%@", @ "12345"];

NSLog (@ "Rsaexchange%d", [str length]);
NSData *strdata = [
pubstr datausingencoding:nsutf8stringencoding];

NSString *encryptstr = [R Rsa_encryptusingserverpublickeywithdata:strdata];
Decrypt:
nsstring *rsa_string = @ "xxxxxx";
Rsacryptor *r = [Rsacryptor shareinstance];

NSData *base64fromstring = [rsa_string datausingencoding:nsutf8stringencoding];

NSString *rsa_decryptdata = [R Rsa_decryptusingprivatekeywithdata:base64fromstring];
NSLog (@ "Rsa_decryptdata%@", rsa_decryptdata);

Ios-rsa and decryption sharing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.