public abstract class SM4Util extends GMBaseUtil
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
ALGORITHM_NAME |
static String |
ALGORITHM_NAME_CBC_NOPADDING |
static String |
ALGORITHM_NAME_CBC_PADDING |
static String |
ALGORITHM_NAME_ECB_NOPADDING |
static String |
ALGORITHM_NAME_ECB_PADDING |
static int |
DEFAULT_KEY_SIZE |
protected static org.slf4j.Logger |
logger |
static String |
SM4_IV_PARAMETER_SPEC |
static String |
SM4_SECRET_KEY_SPEC |
| 构造器和说明 |
|---|
SM4Util() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decryptAsCBCType(byte[] bytes,
byte[] keyValue,
byte[] ivParameter) |
static byte[] |
decryptAsCBCType(byte[] bytes,
String keyValue,
String ivParameter) |
static String |
decryptBase64AsCBCType(String str,
byte[] keyValue,
byte[] ivParameter) |
static String |
decryptBase64AsCBCType(String str,
String keyValue,
String ivParameter) |
static byte[] |
decryptCbcNoPadding(byte[] key,
byte[] iv,
byte[] cipherText) |
static byte[] |
decryptCbcPadding(byte[] key,
byte[] iv,
byte[] cipherText) |
static byte[] |
decryptEcbNoPadding(byte[] key,
byte[] cipherText) |
static byte[] |
decryptEcbPadding(byte[] key,
byte[] cipherText) |
static byte[] |
doCBCMac(byte[] key,
byte[] iv,
org.bouncycastle.crypto.paddings.BlockCipherPadding padding,
byte[] data) |
static byte[] |
doCBCMac(byte[] key,
byte[] iv,
byte[] data)
默认使用PKCS7Padding/PKCS5Padding填充的CBCMAC
|
static byte[] |
doCMac(byte[] key,
byte[] data) |
static byte[] |
doGMac(byte[] key,
byte[] iv,
int tagLength,
byte[] data) |
static byte[] |
encryptAsCBCType(byte[] bytes,
byte[] keyValue,
byte[] ivParameter) |
static byte[] |
encryptAsCBCType(byte[] bytes,
String keyValue,
String ivParameter) |
static String |
encryptAsCBCTypeAsBase64(String str,
byte[] keyValue,
byte[] ivParameter) |
static String |
encryptAsCBCTypeAsBase64(String str,
String keyValue,
String ivParameter) |
static byte[] |
encryptCbcNoPadding(byte[] key,
byte[] iv,
byte[] data) |
static byte[] |
encryptCbcPadding(byte[] key,
byte[] iv,
byte[] data) |
static byte[] |
encryptEcbNoPadding(byte[] key,
byte[] data) |
static byte[] |
encryptEcbPadding(byte[] key,
byte[] data) |
static Cipher |
generateCbcCipher(String algorithmName,
int mode,
byte[] key,
byte[] iv) |
static Cipher |
generateEcbCipher(String algorithmName,
int mode,
byte[] key) |
static byte[] |
generateKey() |
static byte[] |
generateKey(int keySize) |
protected static final org.slf4j.Logger logger
public static final int DEFAULT_KEY_SIZE
public static byte[] generateKey()
throws NoSuchAlgorithmException,
NoSuchProviderException
public static byte[] generateKey(int keySize)
throws NoSuchAlgorithmException,
NoSuchProviderException
public static byte[] encryptEcbPadding(byte[] key,
byte[] data)
throws InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
public static byte[] decryptEcbPadding(byte[] key,
byte[] cipherText)
throws IllegalBlockSizeException,
BadPaddingException,
InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException
public static byte[] encryptEcbNoPadding(byte[] key,
byte[] data)
throws InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
public static byte[] decryptEcbNoPadding(byte[] key,
byte[] cipherText)
throws IllegalBlockSizeException,
BadPaddingException,
InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException
public static byte[] encryptCbcPadding(byte[] key,
byte[] iv,
byte[] data)
throws InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException,
InvalidAlgorithmParameterException
public static byte[] decryptCbcPadding(byte[] key,
byte[] iv,
byte[] cipherText)
throws IllegalBlockSizeException,
BadPaddingException,
InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException,
InvalidAlgorithmParameterException
public static byte[] encryptCbcNoPadding(byte[] key,
byte[] iv,
byte[] data)
throws InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException,
InvalidAlgorithmParameterException
public static byte[] decryptCbcNoPadding(byte[] key,
byte[] iv,
byte[] cipherText)
throws IllegalBlockSizeException,
BadPaddingException,
InvalidKeyException,
NoSuchAlgorithmException,
NoSuchProviderException,
NoSuchPaddingException,
InvalidAlgorithmParameterException
public static byte[] doCMac(byte[] key,
byte[] data)
throws NoSuchProviderException,
NoSuchAlgorithmException,
InvalidKeyException
public static byte[] doGMac(byte[] key,
byte[] iv,
int tagLength,
byte[] data)
public static byte[] doCBCMac(byte[] key,
byte[] iv,
byte[] data)
key - 密码iv - ivdata - 待加密数据public static byte[] doCBCMac(byte[] key,
byte[] iv,
org.bouncycastle.crypto.paddings.BlockCipherPadding padding,
byte[] data)
throws Exception
key - 密码iv - ivpadding - 可以传null,传null表示NoPadding,由调用方保证数据必须是BlockSize的整数倍data - 待加密数据Exception - 异常public static Cipher generateEcbCipher(String algorithmName, int mode, byte[] key) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException
public static Cipher generateCbcCipher(String algorithmName, int mode, byte[] key, byte[] iv) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException
public static String encryptAsCBCTypeAsBase64(String str, byte[] keyValue, byte[] ivParameter)
public static String encryptAsCBCTypeAsBase64(String str, String keyValue, String ivParameter)
public static String decryptBase64AsCBCType(String str, byte[] keyValue, byte[] ivParameter)
public static String decryptBase64AsCBCType(String str, String keyValue, String ivParameter)
public static byte[] encryptAsCBCType(byte[] bytes,
byte[] keyValue,
byte[] ivParameter)
public static byte[] encryptAsCBCType(byte[] bytes,
String keyValue,
String ivParameter)
public static byte[] decryptAsCBCType(byte[] bytes,
byte[] keyValue,
byte[] ivParameter)
Copyright © 2025 姹熻嫃鍗楀ぇ鍏堣吘淇℃伅浜т笟鑲′唤鏈夐檺鍏徃. All rights reserved.