不多说,直接上代码,对称加密只有一个密钥。用他来加密,也用它来解密。
package com.example.shirotest.utils;
import org.apache.tomcat.util.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
public class AESKeyPairUtils {
public static void main(String[] args) {
String content = "www.baidu.com";
String password = "123";
System.out.println("加密之前:" + content);
// 加密
byte[] encrypt = AESKeyPairUtils.encrypt(content, password);
System.out.println("加密后的内容:" + new String(encrypt));
// 解密
String msg = AESKeyPairUtils.decrypt(encrypt, password);
System.out.println("解密后的内容:" + new String(msg));
}
/**
* AES加密字符串
* @param content 需要被加密的字符串
* @param