"Java Coding Guidelines" の#12 do not use insecure or weak encryption algorithms

Source: Internet
Author: User
Tags java se

Applications with high security requirements must avoid unsafe or weak cryptographic algorithms, and the computational power of modern computers allows attackers to break down weak algorithms by brute force. For example, the Data Encryption Standard Algorithm des is extremely restless, using a computer similar to the EFF (Electronic Frontier foundaton) deep crack to be able to violently hack messages encrypted by Des in one day.


[Code Demo sample that does not meet security requirements]

The following code encrypts a string using a weak des algorithm:

Secretkey key = Keygenerator.getinstance ("DES"). GenerateKey (); Cipher Cipher = cipher.getinstance ("DES"); Cipher.init (Cipher.encrypt_mode, key);//encode bytes as UTF8;  strtobeencrypted contains//The input string is encryptedbyte[] encoded = strtobeencrypted.getbytes ("UTF-8");// Perform encryptionbyte[] encrypted = cipher.dofinal (encoded);


[Security-compliant solutions]

This scenario uses a more secure AES encryption algorithm to encrypt the string

Cipher Cipher = cipher.getinstance ("AES"); Keygenerator KGen = keygenerator.getinstance ("AES"); Kgen.init (+);//192 and-bits may unavailablesecretkey skey = Kgen.generatekey (); byte[] raw = skey.getencoded (); Secretkeyspec Skeyspec = new Secretkeyspec (Raw, "AES") Cipher.init (Cipher.encrypt_mode, skeyspec);//Encode bytes as UTF8;  strtobeencrypted contains the//input string that was to be encryptedbyte[] encoded = strtobeencrpyted.getbytes ("UTF-8");// Perform encryptionbyte[] encrypted = cipher.dofinal (encoded);


[Availability]

The use of mathematical and computational insecure cryptographic algorithms can lead to the disclosure of sensitive information. Weak encryption algorithms can be enabled in Java SE 7, and they can be used in scenarios where encryption agrees to be cracked. For example, the ROT13 encryption algorithm is widely used in electronic bulletin boards and Web pages, where the purpose of encryption is to protect people from the interference of information, rather than protect the information is not known to people.


--Welcome reprint, please indicate the source http://blog.csdn.net/asce1885 , do not use for commercial purposes without my permission, thank you--

"Java Coding Guidelines" の#12 do not use insecure or weak encryption algorithms

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.