工作中接触到了SM4,AES,RSA等算法的加解密,这里整理下来,以备后续其他地方需要使用到。
主要用到的第三方包为hutool
后台引入依赖的方式为:
<!-- hutool工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<!-- 加解密 -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
</dependency>
Android端引入依赖的方式为:
//bre-tlv
implementation 'com.payneteasy:ber-tlv:1.0-11'
//hutool
implementation 'cn.hutool:hutool-all:5.7.20'
//加解密
implementation 'org.bouncycastle:bcprov-jdk15on:1.68'
Aes加解密的方法整理如下
package com.unionpay.iottrust.authentication.utils;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
impor