You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.1 KiB

package com.zky.bjca;
import cn.org.bjca.client.exceptions.*;
import cn.org.bjca.client.security.SecurityEngineDeal;
public final class Sign {
public static byte[] DataSign(String strSrc) {
SecurityEngineDeal.setProfilePath("D:\\Java\\program\\newProgram\\zhyw\\web\\config\\config2");
SecurityEngineDeal sed;
byte[] signedValueByte = new byte[0];
try {
sed = SecurityEngineDeal.getInstance("SVSDefault");
byte[] data = strSrc.getBytes();
String signedValue = sed.signData(data);
signedValueByte = sed.base64Decode(signedValue);
// System.out.println(signedValue);
} catch (SVSConnectException | ApplicationNotFoundException | InitException | ParameterTooLongException e) {
e.printStackTrace();
}
return signedValueByte;
}
public static boolean DataSignVerify(String str, String signValue) {
//传入两个参数:
//第一个参数为需要签名的字符串
//第二个参数为签名结果
SecurityEngineDeal.setProfilePath("D:\\Java\\program\\newProgram\\zhyw\\web\\config\\config2");
SecurityEngineDeal sed;
boolean verifyRes = false;
try {
sed = SecurityEngineDeal.getInstance("SVSDefault");
String cert = sed.getServerCertificate();
System.out.println(cert);
verifyRes = sed.verifySignedData(cert, str, signValue);
System.out.println(verifyRes);
} catch (SVSConnectException | ApplicationNotFoundException | InitException | ParameterTooLongException | ParameterInvalidException | UnkownException e) {
e.printStackTrace();
}
return verifyRes;
}
public static byte[] FileSign(String strSrc) {
SecurityEngineDeal.setProfilePath("D:\\Java\\program\\newProgram\\zhyw\\web\\config\\config2");
SecurityEngineDeal sed;
byte[] signedValueByte = new byte[0];
try {
sed = SecurityEngineDeal.getInstance("SVSDefault");
//byte[] data = strSrc.getBytes();
String signedValue = sed.signFile(strSrc);
signedValueByte = sed.base64Decode(signedValue);
// System.out.println(signedValue);
} catch (SVSConnectException | ApplicationNotFoundException | InitException e) {
e.printStackTrace();
}
return signedValueByte;
}
public static boolean FileSignVerify(String str, String signValue) {
SecurityEngineDeal.setProfilePath("D:\\Java\\program\\newProgram\\zhyw\\web\\config\\config2");
SecurityEngineDeal sed;
boolean verifyRes = false;
try {
sed = SecurityEngineDeal.getInstance("SVSDefault");
String cert = sed.getServerCertificate();
System.out.println(cert);
verifyRes = sed.verifySignedFile(cert, str, signValue);
System.out.println(verifyRes);
} catch (SVSConnectException | ApplicationNotFoundException | InitException | ParameterTooLongException | ParameterInvalidException | UnkownException e) {
e.printStackTrace();
}
return verifyRes;
}
}