Delphi調用動態庫

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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章