unit UnitMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type result_param_s = record issuer:array [0..256] of char; //* 颁发者DN*/ serialNumber:array [0..39] of char; //* 证书序列号*/ subject: array [0..255] of char; //* 证书主题*/ notBefore:array [0..19] of char; //* 证书有效期起始时间*/ notAfter :array [0..19] of char; //* 证书有效期的终止时间*/ signresult :array [0..19] of char; //* 签名结果*/ returnCert :array [0..2047] of char; //* 证书Der编码*/ iCertLen:Integer; //* 证书Der编码长度*/ end; presult_param_s=^result_param_s; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; function initMulti:integer;stdcall;external 'netsignagent.dll'; // function NewSocket( // hostName:pchar; // port:Integer; // var sockFd:Integer):Integer;stdcall;external 'netsignagent.dll'; function NewSocket( hostName:pchar; port:Integer; sockFd:pointer):Integer;stdcall;external 'netsignagent.dll'; function CloseSocket( sockFd:pointer):integer;stdcall;external 'netsignagent.dll'; function INS_AttachedSign( sockFd:integer; plain:pchar; iPlainLen:integer; signCertDN:PChar; digestAlg:PChar; crypto:pchar; iCryptoLen:pointer):integer;stdcall;external 'netsignagent.dll'; function INS_AttachedVerify( sockFd:integer; crypto:pchar; iCryptoLen:Integer; iReturnCert:Integer; plain :pchar; iPlainLen:pointer; result:pointer):Integer ;stdcall;external 'netsignagent.dll'; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var conn: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=INFOSEC Technologies SM2ID,CN=中文sm2@0123@test'; soustr := '909CE48D7ABF46395A9EDD8EC6E27B5A'; isoustrLen := Length(soustr); MessageBox(handle, PChar('isoustrLen:' + IntToStr(isoustrLen)),'', MB_OK); ShowMessage(PChar('isoustrLen:' + IntToStr(isoustrLen))); conn := initMulti(); if conn=0 then Application.MessageBox('初始化并发连接操作成功', ''); hostname := PAnsiChar('192.168.2.222'); port := 1111; // res:=NewSocket(hostName, port, sockFd); res:=NewSocket(hostName, port, @sockFd); Application.MessageBox(PChar('NewSocket res:' + IntToStr(res)), ''); if res = 0 then begin iCryptoLen := 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_AttachedSign res:' + 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.
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。