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