1.高级加密标准(AES,Advanced Encryption Standard)为最常见的对称加密算法。对称加密算法也就是加密和解密用相同的密钥。
package cn.com.test;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
public class AES {
private static final String KEY = "a1b2c3d4e5f6g7h8";
private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";
public static void main(String[] args) throws Exception {
String content = "123456";
String s = aesEncrypt(content, KEY);
System.out.println("sagfasdgfasd" + s);
String decrypt = aesDecrypt(s, KEY);
System.out.println("解密后:" + decrypt);
}
public static String base64Encode(byte[] bytes) {
return Base64.encodeBase64String(bytes);
}
public static byte[] base64Decode(String base64Code) throws Exception {
return new BASE64Decoder().decodeBuffer(base64Code);
}