p1 p7签名兼容RSA、SM2

This commit is contained in:
yihzhou
2023-05-18 16:45:32 +08:00
parent ca32bb4c18
commit 10622bfb23
6 changed files with 308 additions and 119 deletions
+114 -104
View File
@@ -1,127 +1,137 @@
<?xml version="1.0" encoding="UTF-8" ?>
<packet extend="base">
<req>
<req>
<command>
<bin>8003</bin>
</command>
<data extend="data">
<rFlag len="1" required="false" cn="RSA标志">
可选,存在,则固定值为‘P’
</rFlag>
<signatureDataType len="1" cn="获取公私钥标记位">
<options>
<option cn="索引方式">
<bin>00</bin>
</option>
<option cn="DN 方式">
<bin>01</bin>
</option>
</options>
</signatureDataType>
<command>
<bin>8003</bin>
</command>
<data extend="data">
<DN cn="DN 或 DN索引">
若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;
</DN>
<algFlag len="1" :value="algFlag()" cn="算法标记">
</algFlag>
<hashFlag len="1" :if="null != $packet.data.hash" cn="外部 hash 标记">
<text>P</text>
</hashFlag>
<signatureDataType len="1" cn="获取公私钥标记位">
<options>
<option cn="索引方式">
<bin>00</bin>
</option>
<option cn="DN 方式">
<bin>01</bin>
</option>
</options>
</signatureDataType>
<hash len="32" :if="null != $packet.data.hash" cn="外部 hash">
</hash>
<DN cn="DN 或 DN索引">
若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;
</DN>
<dataLength len="2" :value="dataLen()" cn="待签名数据长度">
待签名数据长度
</dataLength>
<hashFlag len="1" :if="null != $packet.data.hash" :value="flag()" cn="外部 hash 标记">
</hashFlag>
<signData cn="待签名数据">
待签名数据
</signData>
<hash len="32" :if="null != $packet.data.hash" cn="外部 hash">
</hash>
</data>
<dataLength len="2" :value="dataLen()" :if="null == $packet.data.hash" cn="待签名数据长度">
待签名数据长度
</dataLength>
<signData cn="待签名数据" :if="null == $packet.data.hash">
待签名数据
</signData>
</data>
</req>
<res>
</req>
<res>
<command>
<bin>8004</bin>
</command>
<data>
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
<options>
<option cn="无错误">
<hex>00</hex>
</option>
<option cn="无效的私钥类型">
<hex>03</hex>
</option>
<option cn="无效私钥标记">
<hex>04</hex>
</option>
<option cn="无效的哈希标识">
<hex>05</hex>
</option>
<option cn="无效的签名标识">
<hex>06</hex>
</option>
<option cn="无效的附加标识">
<hex>07</hex>
</option>
<option cn="LMK 错误">
LMK 错误;报告给管理员。
<hex>13</hex>
</option>
<option cn="输入数据错">
<hex>15</hex>
</option>
<option cn="DSP 错误">
DSP 错误;报告给管理员。
<hex>47</hex>
</option>
<option cn="私钥错误">
私钥错误;报告给管理员。
<hex>49</hex>
</option>
<option cn="无效摘要信息语法(仅仅无哈希模式)">
<hex>74</hex>
</option>
<option cn="公钥长度错误">
<hex>76</hex>
</option>
<option cn="私钥长度错误">
<hex>78</hex>
</option>
<option cn="输入数据长度错误">
<hex>80</hex>
</option>
</options>
</error>
<command>
<bin>8004</bin>
</command>
<data>
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
<options>
<option cn="无错误">
<hex>00</hex>
</option>
<option cn="无效的私钥类型">
<hex>03</hex>
</option>
<option cn="无效私钥标记">
<hex>04</hex>
</option>
<option cn="无效的哈希标识">
<hex>05</hex>
</option>
<option cn="无效的签名标识">
<hex>06</hex>
</option>
<option cn="无效的附加标识">
<hex>07</hex>
</option>
<option cn="LMK 错误">
LMK 错误;报告给管理员。
<hex>13</hex>
</option>
<option cn="输入数据错">
<hex>15</hex>
</option>
<option cn="DSP 错误">
DSP 错误;报告给管理员。
<hex>47</hex>
</option>
<option cn="私钥错误">
私钥错误;报告给管理员。
<hex>49</hex>
</option>
<option cn="无效摘要信息语法(仅仅无哈希模式)">
<hex>74</hex>
</option>
<option cn="公钥长度错误">
<hex>76</hex>
</option>
<option cn="私钥长度错误">
<hex>78</hex>
</option>
<option cn="输入数据长度错误">
<hex>80</hex>
</option>
</options>
</error>
<signatureLen len="2" cn="签名的字节长度">
签名的字节长度
</signatureLen>
<signatureLen len="2" cn="签名的字节长度">
签名的字节长度
</signatureLen>
<signature :len="signatureLen()" cn="签名的 DER 编码">
签名的 DER 编码
</signature>
<signature :len="signatureLen()" cn="签名的 DER 编码">
签名的 DER 编码
</signature>
<tailSep len="1" required="false" cn="尾分隔">
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
<hex>19</hex>
</tailSep>
<tailSep len="1" required="false" cn="尾分隔">
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
<hex>19</hex>
</tailSep>
<tail maxLen="32" required="false" cn="尾部">
可选项。最大长度为 32个字符。
</tail>
</data>
<tail maxLen="32" required="false" cn="尾部">
可选项。最大长度为 32个字符。
</tail>
</data>
</res>
<script type="javascript"><![CDATA[
</res>
<script type="javascript"><![CDATA[
function algFlag(){
if( 'P' == $packet.data.rFlag ) {
return ''
} else {
$packet.data.rFlag
}
}
function flag(){
return $packet.data.rFlag;
}
function dataLen(){
def len = $packet.data.signData.length
def ret = new byte[2]
+17 -3
View File
@@ -6,6 +6,10 @@
<bin>8004</bin>
</command>
<data extend="data">
<algFlag len="1" :value="algFlag()" cn="算法标记">
</algFlag>
<signatureDataType len="1" cn="获取公私钥标记位">
<options>
<option cn="索引方式">
@@ -32,8 +36,7 @@
标志为2 时存在
</organizationNum>
<hashFlag len="1" :if="null != $packet.data.hash" cn="外部 hash 标记">
<text>P</text>
<hashFlag len="1" :if="null != $packet.data.hash" :value="flag()" cn="外部 hash 标记">
</hashFlag>
<hash len="32" :if="null != $packet.data.hash" cn="外部 hash">
@@ -132,7 +135,18 @@
</res>
<script><![CDATA[
function dataLen(){
function algFlag(){
if( 'P' == $packet.data.rFlag ) {
return ''
} else {
$packet.data.rFlag
}
}
function flag(){
return $packet.data.rFlag;
}
function dataLen(){
def len = $packet.data.odata.length
def ret = new byte[2]
ret[0] = (byte)(len >> 8 & 0xFF)