import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.CharEncoding; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.spec.SecretKeySpec; import java.security.Key; import java.security.SecureRandom; import java.security.Security; import java.util.Arrays; public class Sm4Util { private static final String ENCODING = CharEncoding.UTF_8; public static final String ALGORITHM_NAME = "SM4"; public static final String ALGORITHM_NAME_ECB_PADDING = "SM4/ECB/PKCS5Padding"; public static final int DEFAULT_KEY_SIZE = 128; public static final String BC = "BC"; public Sm4Util() { } /** * 生成密钥 * * @return * @throws Exception */ public static String generateKey() throws Exception { return new String(Hex.en
记录java实现SM4算法
于 2022-11-11 17:11:45 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)