修改6A、6B接口的参数byte[]为String

This commit is contained in:
zb 2022-04-13 14:34:22 +08:00
parent b4bdf191de
commit 8bb86fdb95
5 changed files with 56 additions and 14 deletions

Binary file not shown.

View File

@ -226,7 +226,7 @@ public interface SydGenApi {
* SessionKey 本地LMK 加密的会话密钥HEX 格式, 本地 LMK 加密的会话密钥长度HEX 格式(不包括第 1 个字符)一般为 33 Bytes默认输入值为缓冲区的大小
* KCV 会话密钥的检验值HEX 格式长度为 32H
*/
RetWrap generateDEByDn(byte[] certSerial, String oData);
RetWrap generateDEByDn(String certSerial, String oData);
/**
* 产生对称密钥通过公钥加密生成网联格式的数字信封
@ -308,7 +308,7 @@ public interface SydGenApi {
* KCV 会话密钥的检验值HEX 格式长度为 36H
* orgCode 如果有机构码的话会返回机构码
*/
RetWrap decryptDEByDN(byte[] certSerial, String pCipherKey);
RetWrap decryptDEByDN(String certSerial, String pCipherKey);
/**
* 接收用私钥解密数字信封还原对称密钥

View File

@ -2194,8 +2194,14 @@ public class SydApi4j implements SydApi {
}
@Override
public RetWrap generateDEByDn(byte[] certSerial, String oData) {
return generateDE(certSerial, 3, 1, oData);
public RetWrap generateDEByDn(String certSerial, String oData) {
byte[] dnBytes = null;
try {
dnBytes = certSerial.getBytes("gbk");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return generateDE(dnBytes, 3, 1, oData);
}
@Override
@ -2308,8 +2314,14 @@ public class SydApi4j implements SydApi {
}
@Override
public RetWrap decryptDEByDN(byte[] certSerial, String pCipherKey) {
return decryptDE(true, 1, certSerial, pCipherKey);
public RetWrap decryptDEByDN(String certSerial, String pCipherKey) {
byte[] dnBytes = null;
try {
dnBytes = certSerial.getBytes("gbk");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return decryptDE(true, 1, dnBytes, pCipherKey);
}
// 测试通过

View File

@ -1430,12 +1430,12 @@ public class TestAllMethods {
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
String oData = "00001111222233";
RetWrap retWrap = api.generateDEByDn(dn.getBytes("gbk"), oData);
RetWrap retWrap = api.generateDEByDn(dn, oData);
String CipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
printRetWrap(retWrap);
RetWrap retWrap1 = api.decryptDEByDN(dn.getBytes("gbk"), CipherKey);
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
printRetWrap(retWrap1);
}

View File

@ -126,13 +126,43 @@ public class TestHT {
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
String oData = "00001111222233";
RetWrap retWrap = api.generateDEByDn(dn.getBytes("gbk"), oData);
String CipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
printRetWrap(retWrap);
RetWrap retWrap = api.generateDEByDn(dn, oData);
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
System.out.println("数字信封: " + cipherKey);
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
System.out.println("原数据: " + retWrap1.get("oData"));
}
/**
* 流程演示
*/
@Test
public void testProcess() {
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
String orgData = "111111213323143243243";
// 签名
String sign = api.attachedSign(orgData.getBytes(), dn);
System.out.println("签名结果: " + sign);
// 生成数字信封
RetWrap retWrap = api.generateDEByDn(dn, sign);
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
System.out.println("数字信封: " + cipherKey);
// 解密数字信封
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
String oData = (String) retWrap1.get("oData");
System.out.println("原数据: " + retWrap1.get("oData"));
// 验签
RetWrap verify = api.attachedVerifyAndGetAll(oData);
if (verify != null) {
System.out.println("x509公钥: " + Util.bytes2HexString(((X509)verify.get("x509")).getPubKey()));
System.out.println("签名原数据: " + verify.get("oData"));
}
RetWrap retWrap1 = api.decryptDEByDN(dn.getBytes("gbk"), CipherKey);
printRetWrap(retWrap1);
}
// 测试通过