unitUnitMain;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeresult_param_s=recordissuer:array[0..256]ofchar;//*颁发者DN*/serialNumber:array[0..39]ofchar;//*证书序列号*/subject:array[0..255]ofchar;//*证书主题*/notBefore:array[0..19]ofchar;//*证书有效期起始时间*/notAfter:array[0..19]ofchar;//*证书有效期的终止时间*/signresult:array[0..19]ofchar;//*签名结果*/returnCert:array[0..2047]ofchar;//*证书Der编码*/iCertLen:Integer;//*证书Der编码长度*/end;presult_param_s=^result_param_s;TForm1=class(TForm)Button1:TButton;procedureButton1Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;functioninitMulti:integer;stdcall;external'netsignagent.dll';//functionNewSocket(//hostName:pchar;//port:Integer;//varsockFd:Integer):Integer;stdcall;external'netsignagent.dll';functionNewSocket(hostName:pchar;port:Integer;sockFd:pointer):Integer;stdcall;external'netsignagent.dll';functionCloseSocket(sockFd:pointer):integer;stdcall;external'netsignagent.dll';functionINS_AttachedSign(sockFd:integer;plain:pchar;iPlainLen:integer;signCertDN:PChar;digestAlg:PChar;crypto:pchar;iCryptoLen:pointer):integer;stdcall;external'netsignagent.dll';functionINS_AttachedVerify(sockFd:integer;crypto:pchar;iCryptoLen:Integer;iReturnCert:Integer;plain:pchar;iPlainLen:pointer;result:pointer):Integer;stdcall;external'netsignagent.dll';implementation{$R*.dfm}procedureTForm1.Button1Click(Sender:TObject);varconn:Integer;hostName:pchar;port:Integer;sockFd:integer;res:Integer;soustr:string;isoustrLen:Integer;signCertDN:string;crypto:pchar;iCryptoLen:Integer;result:result_param_s;iReturnCert:Integer;plain:pchar;iplainLen:Integer;begin//signCertDN:=PChar('O=hoary,CN=inCRL');//signCertDN:='CN=5year,O=syn080924,C=cn';signCertDN:=PChar('O=infosec,CN=nocrl');//signCertDN:='C=cn,O=INFOSECTechnologiesSM2ID,CN=中文sm2@0123@test';soustr:='909CE48D7ABF46395A9EDD8EC6E27B5A';isoustrLen:=Length(soustr);MessageBox(handle,PChar('isoustrLen:'+IntToStr(isoustrLen)),'',MB_OK);ShowMessage(PChar('isoustrLen:'+IntToStr(isoustrLen)));conn:=initMulti();ifconn=0thenApplication.MessageBox('初始化并发连接操作成功','');hostname:=PAnsiChar('192.168.2.222');port:=1111;//res:=NewSocket(hostName,port,sockFd);res:=NewSocket(hostName,port,@sockFd);Application.MessageBox(PChar('NewSocketres:'+IntToStr(res)),'');ifres=0thenbeginiCryptoLen:=409600;GetMem(crypto,409600);Application.MessageBox(PChar('sockFd:'+IntToStr(sockFd)),'');Application.MessageBox(PChar('soustr:'+soustr),'soustr');//签名res:=INS_AttachedSign(sockFd,PAnsiChar(soustr),isoustrLen,PAnsiChar(signCertDN),PAnsiChar(''),crypto,@iCryptoLen);Application.MessageBox(PChar('INS_AttachedSignres:'+IntToStr(res)),'');iReturnCert:=0;iplainLen:=409600;GetMem(plain,409600);//验签res:=INS_AttachedVerify(sockFd,crypto,iCryptoLen,iReturnCert,plain,@iplainLen,@result);Application.MessageBox(PChar('INS_AttachedVerify:'+IntToStr(res)),'');Application.MessageBox(PChar('plain:'+plain),'');end;CloseSocket(@sockFd);end;end.