RSA encryption and decryption problem

Source: Internet
Author: User

The data is encrypted for security reasons in the project, and RSA is used to encrypt it.
Summarized as follows:
Features: Public key encryption private key decryption, private key signature public key authentication, public key is generated through the private key.
Advantages: Asymmetric encryption, high security;
Disadvantage: Encryption and decryption efficiency is low, the cost of performance is therefore not suitable for large amounts of data to encrypt.
Problem:
One: Length problem
RSA limits the encryption and decryption content according to the different private key lengths, generally, the content of the encryption long team = Private key long team/8, but there is also a problem here is the alignment also occupies a certain space, the general alignment is occupied by 11 bytes, so the final plaintext length =1024 ( Assuming a 1024 key length is used/8-11 = 117, the redaction length cannot exceed 117, and the decryption length is 128.
What if the length of the plaintext exceeds the limit? In general, we will solve this problem by means of piecewise encryption and decryption.
Here you can use this library Https://github.com/Blankj/AndroidUtilCode
Second: Decryption Note:
To correctly decrypt the content you need to pay attention to a few things:
1: The key is correct, the encryption and decryption key must be a pair.
2: If the use of segmented encryption, also must be segmented decryption.
3: Key encoding format, cipher code format, alignment is what.
If the key is Base64 encoded then the same way is used to decode the base64 before decrypting it.
Only the encryption and decryption are fully symmetric to get the data correctly.

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.