微信退款通知ase信息解码

package com.mmall.util;

import java.security.Security;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;


public class AESUtils {

    public static final String ALGORITHM = "AES/ECB/PKCS7Padding"; 
    
    
    public static String encode(String data,String key) throws Exception{
        Security.addProvider(new BouncyCastleProvider());
        String md5Key = DigestUtils.md5Hex(key).toLowerCase();
        SecretKeySpec keySpec = new SecretKeySpec(md5Key.getBytes(), "AES");
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, keySpec);
        byte[] encode = Base64.encodeBase64(cipher.doFinal(data.getBytes()));
        return new String(encode,"UTF-8");
    }
    
    
    public static String decode(String data,String key) throws Exception{
       byte[] decodeBase64 = Base64.decodeBase64(data);
       String md5Key = DigestUtils.md5Hex(key).toLowerCase();
       Security.addProvider(new BouncyCastleProvider());
       Cipher cipher = Cipher.getInstance(ALGORITHM);  
       SecretKey keySpec = new SecretKeySpec(md5Key.getBytes(), "AES"); //生成加密解密需要的Key  
       cipher.init(Cipher.DECRYPT_MODE, keySpec);  
       byte[] decoded = cipher.doFinal(decodeBase64);  
       return new String(decoded, "UTF-8");  
    }
    
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值