This article describes the definition and usage of AES implemented in Java. Share it for your reference, as follows:
A brief introduction
1. AES is the most commonly used symmetric encryption algorithm.
2. One of the advantages of AES is that it has not been cracked yet.
3. AES is usually used for mobile communication system encryption and software based on SSH protocol (SSH Client, SecrueCRT).
Two features
1. Advanced
2. DES replacement
Parameter description of three AES
Four code implementation
package com.imooc.security.aes;import java.security.Key;import javax.crypto.Cipher;import javax.crypto.KeyGenerator;import javax.crypto.SecretKey;import javax.crypto.spec.SecretKeySpec;import org.apache.commons.codec.binary.Base64;public class ImoocAES { private static String src = "cakin24 security aes"; public static void main(String[] args) { jdkAES(); } public static void jdkAES() { try { //Generate KEY KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); SecretKey secretKey = keyGenerator.generateKey(); byte[] keyBytes = secretKey.getEncoded(); //Key conversion Key key = new SecretKeySpec(keyBytes, "AES"); //Encryption Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] result = cipher.doFinal(src.getBytes()); System.out.println("jdk aes encrypt : " + Base64.encodeBase64String(result)); //Decrypt cipher.init(Cipher.DECRYPT_MODE, key); result = cipher.doFinal(result); System.out.println("jdk aes desrypt: " + new String(result)); } catch (Exception e) { e.printStackTrace(); } }}Five running effects
jdk aes encrypt : uNOEk3J7FJHB2cXilZluyYciq2NWaYztKfEDNSCjh5g=
jdk aes desrypt : cakin24 security aes
Six application scenarios
Note: org.apache.commons.codec.binary.Base64 package is introduced here, and you can click here to download this site .
PS: Friends who are interested in encryption and decryption can also refer to the online tools of this site:
Text online encryption and decryption tools (including AES, DES, RC4, etc.):
http://tools.VeVB.COM/password/txt_encode
MD5 online encryption tool:
http://tools.VeVB.COM/password/CreateMD5Password
Online hash/hash algorithm encryption tool:
http://tools.VeVB.COM/password/hash_encrypt
Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 encryption tool:
http://tools.VeVB.COM/password/hash_md5_sha
Online sha1/sha224/sha256/sha384/sha512 encryption tool:
http://tools.VeVB.COM/password/sha_encode
For more information about Java related content, please check out the topics of this site: "Summary of Java Mathematical Operation Skills", "Tutorial on Java Data Structures and Algorithms", "Summary of Java Characters and String Operation Skills", "Summary of Java Operation DOM Node Skills" and "Summary of Java Cache Operation Skills"
I hope this article will be helpful to everyone's Java programming.