開發支付寶支付用DELPHI實現 RSA簽名


近來根據業務需求 在ERP中集成了微信支付,支付寶支付,開發支付寶支付時最大的障礙就是RSA簽名,找了很多資料,最終用 下了個libeay32.pas  根據網上資料最終解決了問題

 

 

 

[delphi]  view plain  copy
 
  1. function LoadPrivateKey(filename:string ): PEVP_PKEY;  
  2. var  
  3.   bp : PBIO  ;  
  4.  A,pkey :PEVP_PKEY ;  
  5. begin  
  6.   a:=nil;  
  7.   bp := BIO_new(BIO_s_file()) ;  
  8.   BIO_read_filename(bp, PChar(filename));  
  9.   pkey := PEM_read_bio_PrivateKey(bp, a, nil,NIL);  
  10.   BIO_free(bp);  
  11.   Result:= pkey;  
  12. end;  
  13.   
  14.   
  15.   
  16.   
  17. function Sign(filename,msg : String):string;  
  18. var  
  19.      ctx : EVP_MD_CTX   ;  
  20.      buf_in:Pchar;  
  21.      m_len,outl :cardinal;  
  22.      pKey : PEVP_PKEY;  
  23.      m,buf_out:array   [0..1024]   of   char;  
  24.      p:array   [0..255]   of   char;  
  25.      i:Integer;  
  26.  begin  
  27.  buf_out:='';  
  28.  if filename='' then  
  29.  begin  
  30.    Result:='';  
  31.    Exit;  
  32.  end;  
  33.   pKey := LoadPrivateKey(filename);  
  34.    buf_in := PChar(msg);  
  35.    EVP_MD_CTX_init(@ctx);            //初始化  
  36.    EVP_SignInit(@ctx,EVP_sha1());    //將需要使用的摘要算法存入ctxl中  
  37.     EVP_SignUpdate(@ctx,buf_in,Length(buf_in));//存入編碼值  
  38.    EVP_DigestFinal(@ctx,m,m_len);    //求取編碼的長度為m_len摘要值存入m中  
  39.  rSA_sign(EVP_sha1()._type,m,m_len,buf_out,@outl,pkey.pkey.rsa); //64為SHA1的NID  
  40.  EVP_MD_CTX_cleanup(@ctx);  
  41.   
  42.    Result:=EncodeString(StrPas(buf_out)) ;  
  43.   
  44. 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM