AES-256-GCM Java实现

博客介绍了将代码保存为AES256GCMUtil.java文件后,在对应目录通过命令行操作的方法。包括 -e 加密需原文和密钥两个参数,-d 解密需密文和密钥两个参数。还提到伽罗瓦计数器模式的AES算法加密后密文不一致,但解密会删除随机数。
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.GCMParameterSpec;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Set;

public class AES256GCMUtil {
    private final static String ALGO = "AES_256/GCM/NOPADDING";
    public static final int AES_KEY_SIZE = 256;
    public static final int GCM_IV_LENGTH = 12;
    public static final int TLEN = 128;

    static {
        Set<String> algorithms = Security.getAlgorithms("Cipher");
        if (!algorithms.contains(ALGO)) {
            throw new IllegalArgumentException("AES256 encrypt and decrypy system can not used");
        }
    }
    public static void main(String[] args) throws Exception {
        /* Check Option Format.Option or parameters must is true then process next code*/
        if(args.length == 0) {
        	System.out.println("Option error!You need
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值