添加 BouncyCastle provider
// 添加 BouncyCastle provider
Security.addProvider(new BouncyCastleProvider());
示例
public static void main(String[] args) throws Exception {
// 添加 BouncyCastle provider
Security.addProvider(new BouncyCastleProvider());
// 定义密钥
byte[] keyBytes = "0123456009abcdef".getBytes("UTF-8");
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
// 初始化加密解密器
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
// 执行加密操作
byte[] input = "TEST".getBytes("UTF-8");
byte[] encrypted = cipher.doFinal(input);
// 输出加密结果
System.out.println("Encrypted: " + new String(encrypted, "UTF-8"));
}