3des加密及解密处理

本文介绍了3DES加密和解密的过程,并强调了在实际操作中必须使用Base64编码来避免乱码问题。
摘要由CSDN通过智能技术生成
// 密钥(固定密钥只为测试使用,实际根据项目的密钥)
private final static String secretKey = "c528fb5862b48f03e1ad3d4ee68c670c";
//向量长度必须为8的倍数
private final static String iv = "01234567";
// 编码方式
private final static String encoding = "utf-8";

加密

/**
 * 3des加密
 * @param deviceSecret 需要加密的内容
 * @return
 */
public String Encrypt(String deviceSecret){
    String asciiString = "";
    Key deskey = null;
    try {
        DESedeKeySpec spec = new DESedeKeySpec(secretKey.getBytes());
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
        IvParameterSpec ips = new IvParameterSpec(iv.getBytes());
        cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
        byte[] encryptData = Base64Utils.encode(cipher
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值