AES encryption algorithm with random encryption results under Linux

Source: Internet
Author: User

Special Note: I blog part of the reference network other blogs, but I have personally written and verified through. If you find that the blog has errors, please prompt to avoid misleading other people, thank you! Welcome reprint, but remember to indicate the source of the article: HTTP://WWW.CNBLOGS.COM/MAO2080/1, problem description

AES is used to encrypt data in the project, and tests are normal in a Windows environment, but the data generated after deployment to a Linux server is random. Colleagues looking for long time did not find out, after I decided to roll up the sleeves from the code to start troubleshooting, read the code after the discovery and no strange, how to ask hundred teachers, got a blog related.

2. Solution

Modify the previous code:

1 keygenerator KGen = keygenerator.getinstance ("AES"); 2 New SecureRandom (Password.getbytes ())); 3 Secretkey secretkey = Kgen.generatekey ();

Modified code:

1 keygenerator KGen = keygenerator.getinstance ("AES"); 2 securerandom securerandom = securerandom.getinstance ("sha1prng");   3  Securerandom.setseed (Password.getbytes ());                       4 kgen.init (securerandom); 5 Secretkey secretkey = Kgen.generatekey ();
3, the role of Setseed?

Cond

4. Reference website

8526440

AES encryption algorithm with random encryption results under Linux

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.