Package cn.gmkit.zuc
Class ZUCUtil
java.lang.Object
cn.gmkit.zuc.ZUCUtil
Static convenience entry point for ZUC-128.
This class mirrors ZUC; it exists for users who prefer a utility
naming style consistent with SM2/SM3/SM4 helpers in this module.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intZUC-128 IV length in bytes.static final intZUC-128 key length in bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decrypt(byte[] key, byte[] iv, byte[] ciphertext) 使用 ZUC 对字节密文解密;实现与encrypt(byte[], byte[], byte[])相同。static StringdecryptBase64ToUtf8(String keyHex, String ivHex, String ciphertextBase64) 解密 Base64 密文并按 UTF-8 解码。static StringdecryptHexToUtf8(String keyHex, String ivHex, String ciphertextHex) 解密十六进制密文并按 UTF-8 解码。static String生成兼容入口的 EEA3 字对齐密钥流。static byte[]eea3Encrypt(String keyHex, int count, int bearer, int direction, byte[] message) 按完整消息字节长度执行 EEA3 加密。static byte[]eea3Encrypt(String keyHex, int count, int bearer, int direction, byte[] message, int bitLength) 按指定有效位数执行 3GPP EEA3 加密。static String计算完整消息的 EIA3 兼容 MAC。static String按指定有效位数计算标准 EIA3 MAC。static String按 UTF-8 文本计算完整消息的 EIA3 兼容 MAC。static byte[]encrypt(byte[] key, byte[] iv, byte[] plaintext) 使用 ZUC 对字节消息加密;ZUC 是异或流密码,解密使用同一方法。static StringencryptBase64(String keyHex, String ivHex, String plaintext) 按 UTF-8 文本输入执行 ZUC 加密并返回 Base64 密文。static StringencryptHex(String keyHex, String ivHex, String plaintext) 按 UTF-8 文本输入执行 ZUC 加密并返回十六进制密文。static byte[]keystream(byte[] key, byte[] iv, int lengthBytes) 生成 ZUC 密钥流字节。static StringkeystreamHex(String keyHex, String ivHex, int lengthBytes) 生成十六进制 ZUC 密钥流。static int[]keystreamWords(byte[] key, byte[] iv, int lengthWords) 生成按大端解释的 32 位 ZUC 密钥流字。static StringkeystreamWordsHex(String keyHex, String ivHex, int lengthWords) 生成按大端字序拼接的十六进制密钥流字。
-
Field Details
-
KEY_LENGTH
public static final int KEY_LENGTHZUC-128 key length in bytes.- See Also:
-
IV_LENGTH
public static final int IV_LENGTHZUC-128 IV length in bytes.- See Also:
-
-
Method Details
-
keystream
public static byte[] keystream(byte[] key, byte[] iv, int lengthBytes) 生成 ZUC 密钥流字节。- Parameters:
key- 16 字节密钥iv- 16 字节初始化向量lengthBytes- 输出字节数,不能为负- Returns:
- 密钥流字节
- See Also:
-
keystreamHex
生成十六进制 ZUC 密钥流。- Parameters:
keyHex- 32 个十六进制字符的密钥ivHex- 32 个十六进制字符的 IVlengthBytes- 输出字节数- Returns:
- 小写十六进制密钥流
- See Also:
-
keystreamWords
public static int[] keystreamWords(byte[] key, byte[] iv, int lengthWords) 生成按大端解释的 32 位 ZUC 密钥流字。- Parameters:
key- 16 字节密钥iv- 16 字节初始化向量lengthWords- 输出的 32 位字数量- Returns:
- 无符号 32 位值使用
int承载的数组 - See Also:
-
keystreamWordsHex
生成按大端字序拼接的十六进制密钥流字。- Parameters:
keyHex- 32 个十六进制字符的密钥ivHex- 32 个十六进制字符的 IVlengthWords- 输出的 32 位字数量- Returns:
- 小写十六进制密钥流
- See Also:
-
encrypt
public static byte[] encrypt(byte[] key, byte[] iv, byte[] plaintext) 使用 ZUC 对字节消息加密;ZUC 是异或流密码,解密使用同一方法。- Parameters:
key- 16 字节密钥iv- 16 字节初始化向量plaintext- 明文字节- Returns:
- 密文字节
- See Also:
-
encryptHex
按 UTF-8 文本输入执行 ZUC 加密并返回十六进制密文。- Parameters:
keyHex- 32 个十六进制字符的密钥ivHex- 32 个十六进制字符的 IVplaintext- UTF-8 明文- Returns:
- 小写十六进制密文
- See Also:
-
encryptBase64
按 UTF-8 文本输入执行 ZUC 加密并返回 Base64 密文。- Parameters:
keyHex- 32 个十六进制字符的密钥ivHex- 32 个十六进制字符的 IVplaintext- UTF-8 明文- Returns:
- Base64 密文
- See Also:
-
decrypt
public static byte[] decrypt(byte[] key, byte[] iv, byte[] ciphertext) 使用 ZUC 对字节密文解密;实现与encrypt(byte[], byte[], byte[])相同。- Parameters:
key- 16 字节密钥iv- 16 字节初始化向量ciphertext- 密文字节- Returns:
- 明文字节
- See Also:
-
decryptHexToUtf8
解密十六进制密文并按 UTF-8 解码。- Parameters:
keyHex- 32 个十六进制字符的密钥ivHex- 32 个十六进制字符的 IVciphertextHex- 十六进制密文- Returns:
- UTF-8 明文
- See Also:
-
decryptBase64ToUtf8
解密 Base64 密文并按 UTF-8 解码。- Parameters:
keyHex- 32 个十六进制字符的密钥ivHex- 32 个十六进制字符的 IVciphertextBase64- Base64 密文- Returns:
- UTF-8 明文
- See Also:
-
eea3
生成兼容入口的 EEA3 字对齐密钥流。- Parameters:
keyHex- 32 个十六进制字符的密钥count- 32 位计数器bearer- 5 位承载标识,范围 0 至 31direction- 方向位,只能为 0 或 1bitLength- 需要的有效位数- Returns:
- 字对齐的小写十六进制密钥流
- See Also:
-
eea3Encrypt
public static byte[] eea3Encrypt(String keyHex, int count, int bearer, int direction, byte[] message, int bitLength) 按指定有效位数执行 3GPP EEA3 加密。- Parameters:
keyHex- 32 个十六进制字符的密钥count- 32 位计数器bearer- 5 位承载标识,范围 0 至 31direction- 方向位,只能为 0 或 1message- 消息字节bitLength- 有效消息位数,不能超过消息字节数乘 8- Returns:
- 与有效位数对应的密文字节,末字节未使用位清零
- See Also:
-
eea3Encrypt
public static byte[] eea3Encrypt(String keyHex, int count, int bearer, int direction, byte[] message) 按完整消息字节长度执行 EEA3 加密。- Parameters:
keyHex- 32 个十六进制字符的密钥count- 32 位计数器bearer- 5 位承载标识,范围 0 至 31direction- 方向位,只能为 0 或 1message- 消息字节- Returns:
- 与输入等长的密文字节
- See Also:
-
eia3
计算完整消息的 EIA3 兼容 MAC。- Parameters:
keyHex- 32 个十六进制字符的密钥count- 32 位计数器bearer- 5 位承载标识,范围 0 至 31direction- 方向位,只能为 0 或 1message- 消息字节- Returns:
- 8 个十六进制字符的 MAC
- See Also:
-
eia3
public static String eia3(String keyHex, int count, int bearer, int direction, byte[] message, int bitLength) 按指定有效位数计算标准 EIA3 MAC。- Parameters:
keyHex- 32 个十六进制字符的密钥count- 32 位计数器bearer- 5 位承载标识,范围 0 至 31direction- 方向位,只能为 0 或 1message- 消息字节bitLength- 有效消息位数,不能超过消息字节数乘 8- Returns:
- 8 个十六进制字符的 MAC
- See Also:
-
eia3
按 UTF-8 文本计算完整消息的 EIA3 兼容 MAC。- Parameters:
keyHex- 32 个十六进制字符的密钥count- 32 位计数器bearer- 5 位承载标识,范围 0 至 31direction- 方向位,只能为 0 或 1message- UTF-8 消息文本- Returns:
- 8 个十六进制字符的 MAC
- See Also:
-