400 lines
13 KiB
Java
400 lines
13 KiB
Java
package com.sunyard.inf;
|
||
|
||
|
||
import com.sunyard.RetWrap;
|
||
import com.sunyard.cert.X509;
|
||
|
||
/**
|
||
* 签名验签相关接口
|
||
*/
|
||
public interface SydSVApi extends SydNakedSVApi, SydAttachedSVApi, SydDetachedSVApi{
|
||
|
||
}
|
||
|
||
/**
|
||
* 不经过 CA 授信
|
||
* 直接使用公私钥对签名验签
|
||
*/
|
||
interface SydNakedSVApi {
|
||
/**
|
||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制裸签名(遵循 PKCS#1)
|
||
* @param orgData 待签名的原始数据
|
||
* @param sCertDN 签名者证书 DN
|
||
* @return 签名数据
|
||
*/
|
||
public byte[] SYD_NakedSign(
|
||
byte[] orgData,
|
||
String sCertDN
|
||
);
|
||
|
||
|
||
/**
|
||
* 使用指定的证书 DN,对指定的原始数据编制裸验签(遵循PKCS#1)
|
||
* @param orgData 待签名的原始数据
|
||
* @param sign 签名数据
|
||
* @param sCertDN 签名者证书 DN
|
||
* @return 验签是否通过
|
||
*/
|
||
public boolean SYD_NakedVerify(
|
||
byte[] orgData,
|
||
byte[] sign,
|
||
String sCertDN
|
||
);
|
||
}
|
||
|
||
/**
|
||
* 带原文的签名验签
|
||
*/
|
||
interface SydAttachedSVApi {
|
||
|
||
/**
|
||
* sm2私钥签名
|
||
* 用户id默认为1234567812345678
|
||
* 签名结果R/S序列串先进行der编码,再进行base64编码
|
||
*
|
||
* @param flag 私钥标志位,当为1时第二个参数传入存储私钥的索引,当为0时第二个参数传入私钥
|
||
* @param privateKey 当私钥标志位为1时传入存储私钥的索引,当为0时传入私钥
|
||
* @param publicKey 公钥
|
||
* @param orgData 要签名的信息
|
||
* @return 签名结果
|
||
*/
|
||
String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
|
||
|
||
/**
|
||
* SM2 私钥签名
|
||
* @param pUserID 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||
* @param certNo 证书号
|
||
* @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据
|
||
* @param publicKey 公钥的 DER 编码
|
||
* @param orgData 原始数据
|
||
* @return 签名的 base64 编码
|
||
*/
|
||
String SM2SignC(
|
||
String pUserID,
|
||
String certNo,
|
||
int nOrgDataType,
|
||
byte[] publicKey,
|
||
byte[] orgData
|
||
);
|
||
|
||
/**
|
||
* RSA 私钥签名
|
||
* @param HashMark 哈希标识 指示用于哈希证书数据的哈希算法的标识。0: SHA1 1: SHA256 2: MD5。
|
||
* @param privateKeyTag 私钥标记 指示私钥位置的标记。数字为存储私钥的索引,除了全9表示使用由命令中提供的密钥。
|
||
* 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号
|
||
* @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据
|
||
* @param orgData 原始数据
|
||
* @return 签名的 base64 编码
|
||
*/
|
||
byte[] RSASignC(
|
||
String privateKeyTag,
|
||
int HashMark,
|
||
int nOrgDataType,
|
||
byte[] orgData);
|
||
|
||
|
||
byte[] RSASign(
|
||
String privateKey,
|
||
int HashMark,
|
||
int nOrgDataType,
|
||
byte[] orgData);
|
||
|
||
/**
|
||
* 采用 RSA 算法,用指定的公钥对指定的原始数据进行数字签名验证。
|
||
* @param HashMark 哈希标识
|
||
* @param nOrgDataType 签名方式
|
||
* @param publicKey 公钥
|
||
* @param orgData 原始数据
|
||
* @param sign base64 格式的签名
|
||
* @return true 验签通过 false 验签失败
|
||
*/
|
||
boolean RSAVerify(
|
||
int HashMark,
|
||
int nOrgDataType,
|
||
byte[] publicKey,
|
||
byte[] orgData,
|
||
byte[] sign);
|
||
|
||
/**
|
||
* sm2验签
|
||
* 用户id默认为1234567812345678
|
||
*
|
||
* @param publicKey 公钥的 DER 编码
|
||
* @param orgData 要签名的信息
|
||
* @param base64Sign 计算的签名,签名结果R/S序列串先进行der编码,再进行base64编码后的结果
|
||
* @return true 验签成功,false 验签失败
|
||
*/
|
||
boolean SM2Verify(byte[] publicKey, byte[] orgData, String base64Sign);
|
||
|
||
/**
|
||
* 采用 SM2 算法,用指定的公钥对指定的原始数据进行数字签名验证。
|
||
* @param certNo id 用于计算SM3-HASH
|
||
* @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据,用1.2.3章节限定符亦可
|
||
* @param publicKey 公钥
|
||
* @param orgData 原始数据
|
||
* @param sign base64 格式的签名
|
||
* @return true 验签通过 false 验签失败
|
||
*/
|
||
boolean SM2Verify(
|
||
String certNo,
|
||
int nOrgDataType,
|
||
byte[] publicKey,
|
||
byte[] orgData,
|
||
String sign
|
||
);
|
||
|
||
|
||
/**
|
||
* SM2 私钥签名
|
||
* @param certNo 证书号
|
||
* @param orgData 原始数据
|
||
* @return 签名的 base64 编码
|
||
*/
|
||
String SM2SignCustomized(
|
||
String certNo,
|
||
byte[] orgData
|
||
);
|
||
|
||
/**
|
||
* 采用 SM2 算法,用指定的公钥对指定的原始数据进行数字签名验证。
|
||
* @param certNo 证书号
|
||
* @param orgData 原始数据
|
||
* @param sign base64 格式的签名
|
||
* @return true 验签通过 false 验签失败
|
||
*/
|
||
boolean SM2VerifyCustomized(
|
||
String certNo,
|
||
byte[] orgData,
|
||
String sign
|
||
);
|
||
|
||
/**
|
||
* 带公钥证书与原始数据的数字签名(遵循 PKCS#7)
|
||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制带公钥证书的数字签名(遵循 PKCS#7)。
|
||
*
|
||
* @param orgData 待签名数据
|
||
* @param sCertDN 证书DN
|
||
* @return
|
||
* 符合PKCS7标准的签名结果
|
||
*/
|
||
String attachedSign(byte[] orgData, String sCertDN);
|
||
|
||
/**
|
||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||
*
|
||
* @param sign 已签名数据
|
||
* @return true 验签通过 false 验签失败
|
||
*/
|
||
boolean attachedVerify(String sign);
|
||
|
||
/**
|
||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||
*
|
||
* @param sign 已签名数据
|
||
* @return 成功返回签名的原数据,失败则报错
|
||
*/
|
||
String attachedVerifyRD(String sign);
|
||
|
||
/**
|
||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||
*
|
||
* @param sign 已签名数据
|
||
* @return
|
||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||
*/
|
||
X509 attachedVerifyAndGetX509(String sign);
|
||
|
||
/**
|
||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||
*
|
||
* @param sign 已签名数据
|
||
* @return
|
||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||
*/
|
||
RetWrap attachedVerifyAndGetAll(String sign);
|
||
}
|
||
|
||
|
||
/**
|
||
* 不带原文的签名验签
|
||
*/
|
||
interface SydDetachedSVApi {
|
||
|
||
/**
|
||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||
* @param orgData 待签名的原始数据
|
||
* @param sign 签名数据
|
||
* @return 验签是否通过
|
||
*/
|
||
public boolean SYD_DetachedVerify(
|
||
byte[] orgData,
|
||
String sign);
|
||
|
||
|
||
/**
|
||
* 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7)
|
||
* @param orgData 待签名的原始数据
|
||
* @param sCertDN 签名者证书 DN
|
||
* @return 签名数据
|
||
*/
|
||
public String SYD_DetachedSign(
|
||
byte[] orgData,
|
||
String sCertDN
|
||
);
|
||
|
||
|
||
|
||
/**
|
||
* 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7)
|
||
* 待签名的原始数据将在接口内部进行 sm3 ,然后做 Detach 签名
|
||
* @param orgData 待签名的原始数据
|
||
* @param publicKey sm3 hash 所用的公钥
|
||
* @param sCertDN 签名者证书 DN
|
||
* @return 签名数据
|
||
*/
|
||
public String sm3AndDetachedSign(
|
||
byte[] orgData,
|
||
String publicKey,
|
||
String sCertDN
|
||
);
|
||
|
||
|
||
|
||
/**
|
||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||
* 原始数据将在接口内部进行 sm3 ,然后做 Detach 验签
|
||
* @param orgData 待签名的原始数据
|
||
* @param publicKey sm3 hash 所用的公钥
|
||
* @param sign 签名数据
|
||
* @return 验签是否通过
|
||
*/
|
||
public boolean sm3AndDetachedVerify(
|
||
byte[] orgData,
|
||
String publicKey,
|
||
String sign);
|
||
|
||
/**
|
||
* 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7)
|
||
* 待签名的原始数据将在接口内部进行不带公钥的 sm3 ,然后做 Detach 签名
|
||
* @param orgData 待签名的原始数据
|
||
* @param sCertDN 签名者证书 DN
|
||
* @return 签名数据
|
||
*/
|
||
String sm3WithoutPKDetachedSign(byte[] orgData, String sCertDN);
|
||
|
||
/**
|
||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||
* 原始数据将在接口内部进行无公钥的 sm3 ,然后做 Detach 验签
|
||
*
|
||
* @param orgData 待签名的原始数据
|
||
* @param sign 签名数据
|
||
* @return 验签是否通过
|
||
*/
|
||
boolean sm3WithoutPKDetachedVerify(byte[] orgData, String sign);
|
||
|
||
|
||
/**
|
||
*
|
||
* 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7)
|
||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||
*
|
||
* @param dataType 数据模式,输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||
* @param orgData 输入的数据
|
||
* @param sCertDN 签名者证书 DN
|
||
* @return 签名数据
|
||
*/
|
||
public String detachedSign(
|
||
int dataType,
|
||
byte[] orgData,
|
||
String sCertDN
|
||
);
|
||
|
||
/**
|
||
* 带公钥证书与签名属性的数字签名(遵循 PKCS#7)
|
||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||
* @param keyTag 密钥对应的索引号
|
||
* @return 签名的 DER 编码
|
||
*/
|
||
public byte[] detachedSign(
|
||
int dataType,
|
||
byte[] orgData,
|
||
int keyTag
|
||
);
|
||
|
||
/**
|
||
* 带公钥证书的PKCS#7数字签名(序列号)
|
||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为要签名的信息
|
||
* @param certificateNo X509证书序号
|
||
* @return 符合PKCS7标准的签名结果
|
||
*/
|
||
public String detachedSignbysn(
|
||
int dataType,
|
||
byte[] orgData,
|
||
String certificateNo);
|
||
|
||
|
||
/**
|
||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||
*
|
||
* @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||
* @param orgData 待签名的原始数据
|
||
* @param sign 签名数据
|
||
* @return 验签是否通过
|
||
*/
|
||
boolean detachedVerify(
|
||
int dataType,
|
||
byte[] orgData,
|
||
String sign);
|
||
|
||
/**
|
||
* 带公钥证书与签名属性的数字签名验签(遵循 PKCS#7)
|
||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||
* @param sign 已签名数据
|
||
* @return 是否正确
|
||
*/
|
||
boolean detachedVerify(
|
||
int dataType,
|
||
byte[] orgData,
|
||
byte[] sign);
|
||
|
||
/**
|
||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)返回证书信息
|
||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||
*
|
||
* @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||
* @param orgData 待签名的原始数据
|
||
* @param sign 签名数据
|
||
* @return 证书
|
||
*/
|
||
X509 detachedVerifyAndGetX509(int dataType,
|
||
byte[] orgData,
|
||
String sign);
|
||
|
||
/**
|
||
* 计算SM3散列值
|
||
* @param packSn 消息块号,0=仅一块,1=第一块,2=中间块,3=最后块
|
||
* @param userId 用户 ID,只对“消息块号”为 0、1 时有效
|
||
* @param publicKey 公钥的 DER 编码
|
||
* @param msg 二进制的消息块
|
||
* @param filterData 过渡消息数据,只对“消息块号”为 2、3 时有效
|
||
* @return
|
||
* filterData: 过渡消息数据,只对“消息块号”为 2、1 时有效
|
||
* hash: hash
|
||
*/
|
||
RetWrap SM3Hash(int packSn, String userId, byte[] publicKey, byte[] msg, byte[] filterData);
|
||
|
||
}
|
||
|
||
|
||
|