近來根據業務需求 在ERP中集成了微信支付,支付寶支付,開發支付寶支付時最大的障礙就是RSA簽名,找了很多資料,最終用 下了個libeay32.pas 根據網上資料最終解決了問題
- function LoadPrivateKey(filename:string ): PEVP_PKEY;
- var
- bp : PBIO ;
- A,pkey :PEVP_PKEY ;
- begin
- a:=nil;
- bp := BIO_new(BIO_s_file()) ;
- BIO_read_filename(bp, PChar(filename));
- pkey := PEM_read_bio_PrivateKey(bp, a, nil,NIL);
- BIO_free(bp);
- Result:= pkey;
- end;
- function Sign(filename,msg : String):string;
- var
- ctx : EVP_MD_CTX ;
- buf_in:Pchar;
- m_len,outl :cardinal;
- pKey : PEVP_PKEY;
- m,buf_out:array [0..1024] of char;
- p:array [0..255] of char;
- i:Integer;
- begin
- buf_out:='';
- if filename='' then
- begin
- Result:='';
- Exit;
- end;
- pKey := LoadPrivateKey(filename);
- buf_in := PChar(msg);
- EVP_MD_CTX_init(@ctx); //初始化
- EVP_SignInit(@ctx,EVP_sha1()); //將需要使用的摘要算法存入ctxl中
- EVP_SignUpdate(@ctx,buf_in,Length(buf_in));//存入編碼值
- EVP_DigestFinal(@ctx,m,m_len); //求取編碼的長度為m_len摘要值存入m中
- rSA_sign(EVP_sha1()._type,m,m_len,buf_out,@outl,pkey.pkey.rsa); //64為SHA1的NID
- EVP_MD_CTX_cleanup(@ctx);
- Result:=EncodeString(StrPas(buf_out)) ;
- end;
QQ:24177885
http://blog.csdn.net/star1010/article/details/47809449
http://bbs.2ccc.com/topic.asp?topicid=514109
http://blog.csdn.net/wingleo/article/details/52067838