近来根据业务需求 在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());
- EVP_SignUpdate(@ctx,buf_in,Length(buf_in));
- EVP_DigestFinal(@ctx,m,m_len);
- rSA_sign(EVP_sha1()._type,m,m_len,buf_out,@outl,pkey.pkey.rsa);
- 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
|
请发表评论