一、AES加密是什么?
AES加密,高级加密标准(Advanced Encryption Standard,AES),英文的首字母缩写,也称之为Rijndael加密法,该名字取于AES加密的创始人,AES是一种对称加密算法,对称加密算法简单的说,就是加密和解密用同一个密钥,那么当然也就有分对称加密算法,例如RSA加密算法。
package com.httpclientTest.util;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class AESTest {
private static final String ENCODING = "UTF-8";
/**
* AES加密/不加加密模式和填充模式,用用户密码生成密钥
* @param content 明文
* @param password 密码,用于生成密钥
* @return
*/
public static String encrypt(String content,String password){
try {
//创建AES的Key生产者
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(password.getBytes());
kgen.init(12