小编And*_*ejs的帖子

使用Windows证书存储区中的证书和私钥与OpenSSL

我正在尝试制作一个在Delphi XE中使用某些Web服务的程序.要连接到Web服务,我必须使用自签名证书,该证书存储在Windows证书库中.我使用CertOpenSystemStore打开证书库,获取证书CertFindCertificateInStore并进行设置SSL_CTX_use_certificate.没问题.然后我得到公钥blob CryptExportKey并组成一个私钥,如下所示:

function PrivKeyBlob2RSA(const AKeyBlob: PByte; const ALength: Integer; const ASSLCtx: PSSL_CTX): IdSSLOpenSSLHeaders.PEVP_PKEY;
var
  modulus: PByte;
  bh: PBLOBHEADER;
  rp: PRSAPUBKEY;
  rsa_modlen: DWORD;
  rsa_modulus: PAnsiChar;
  rkey: PRSA;
begin
  bh := PBLOBHEADER(AKeyBlob);
  Assert(bh^.bType = PUBLICKEYBLOB);
  rp := PRSAPUBKEY(AKeyBlob + 8);
  Assert(rp.magic = $31415352);
  rsa_modulus := PAnsiChar(Integer(Pointer(rp))+12);
  rkey := RSA_new_method(ASSLCtx.client_cert_engine);
  rkey^.References := 1;
  rkey^.e := BN_new;
  rkey^.n := BN_new;
  BN_set_word(rkey^.e, rp^.pubexp);
  rsa_modlen := (rp^.bitlen div 8) + 1;
  modulus := AllocMem(rsa_modlen);
  CopyMemory(modulus, rsa_modulus, rsa_modlen);
  RevBuffer(modulus, rsa_modlen);
  BN_bin2bn(modulus, …
Run Code Online (Sandbox Code Playgroud)

windows delphi openssl certificate-store

27
推荐指数
1
解决办法
3478
查看次数

标签 统计

certificate-store ×1

delphi ×1

openssl ×1

windows ×1