Java AES encryption steps

Source: Internet
Author: User

Keygenerator kg = keygenerator. getinstance ("AES"); // get the key generator
Kg. INIT (256); // Initialization
// The DES algorithm must be 56 bits
// The desede algorithm can be 112-bit or 168-bit.
// The AES algorithm can be 128, 192, or 256 bits.
Secretkey key = kg. generatekey (); // you can use multiple methods to save the key.

Encryption:
Cipher CP = cipher. getinstance ("AES"); // create a secret
CP. INIT (Cipher. encrypt_mode, key); // Initialization
String STR = "I am the plaintext to be encrypted ";
Byte [] ptext = Str. getbytes ("utf8 ");
Byte [] ctext = CP. dofinal (ptext); // Encryption
// Multiple storage methods are available.

Decryption:
Cipher CP = cipher. getinstance ("AES"); // create a secret
CP. INIT (Cipher. decrypt_mode, key); // Initialization
Byte [] ptext = CP. dofinal (ctext); // decrypt

String STR = new string (ptext, "utf8"); // re-display the plaintext

Author dipper <reprinted by the author and source retained>
Blog http://blog.csdn.net/mq612

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.