78 lines
2.5 KiB
Java
78 lines
2.5 KiB
Java
package com.sunyard.inf.cryption;
|
|
|
|
import com.sunyard.RetWrap;
|
|
|
|
/**
|
|
* Hash 算法接口
|
|
*/
|
|
public interface SydHashApi {
|
|
|
|
/**
|
|
* 计算SM3散列值
|
|
* @param sn 证书序号
|
|
* @param userId 用户ID
|
|
* @param msg 原始数据,二进制的消息块
|
|
* @return
|
|
*/
|
|
// byte[] SM3HashSNaId(String sn, String userId, byte[] msg);
|
|
|
|
/**
|
|
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
|
* @param publicKey 公钥的 DER 编码(可以为空)
|
|
* @param msg 原始数据,二进制的消息块
|
|
* @param block 消息块标志
|
|
* @param mac 上一轮 mac 值,当 mac 不是 null,长度不为 0,则直接从第二包开始。
|
|
* @return HASH 值,32 个 Bytes.
|
|
*/
|
|
byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac);
|
|
|
|
/**
|
|
* 计算SM3散列值
|
|
* @param publicKey 公钥的 DER 编码 (03420004 开头)
|
|
* @param userId 用户ID
|
|
* @param msg 原始数据,二进制的消息块
|
|
* @return
|
|
*/
|
|
byte[] SM3Hash(String publicKey, String userId, byte[] msg);
|
|
|
|
/**
|
|
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
|
*
|
|
* @param publicKey 公钥(可以为空)
|
|
* @param msg 原始数据
|
|
* @return HASH 值,32 个 Bytes.
|
|
*/
|
|
byte[] SM3Hash(String publicKey, byte[] msg);
|
|
|
|
|
|
/**
|
|
* 输入对指定的原始数据 (无公钥),通过 SM3 算法计算数据的散列值。
|
|
*
|
|
* @param msg 原始数据
|
|
* @return HASH 值,32 个 Bytes.
|
|
*/
|
|
byte[] SM3Hash(byte[] msg);
|
|
|
|
|
|
public byte[] MACCalc(int alg, int keyType, int fullmode, int maclen, String key, byte[] infoData);
|
|
|
|
/**
|
|
* mac 计算
|
|
* @param alg 0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19
|
|
* @param keyType 0-TAK 1-ZAK
|
|
* @param fullMode 0-弱填充 1 强填充
|
|
* @param AK 密钥
|
|
* @param infoData <=1024
|
|
* @param macLen 1=4Byte 2=8Byte 3=16Byte(仅在SM4/AES 下有效)
|
|
* @return mac 值 hex 格式
|
|
*/
|
|
public String MACCalc(int alg, int keyType, String AK, int fullMode, byte[] infoData, int macLen);
|
|
public void MACCheck(int alg, int keyType, String AK, int fullMode, byte[] infoData, String mac);
|
|
|
|
public String calcPBOCMAC(int mode, int keyType, String key, byte[] data, int block, byte[] iv);
|
|
|
|
public RetWrap countHash(int hashType, int packSn, byte[] msg, byte[] filterData);
|
|
|
|
public byte[] itHash(int hashType, byte[] orgData);
|
|
}
|