本文介绍了密码箱 3 无法加载公钥 - 流读取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我用 openssl 生成了一个密钥对

Well i generated a keypair with openssl

openssl genrsa -des3 -out _private.pem 1024

openssl rsa -pubout -in _private.pem -out public.pem

公开

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtdPKdvB/h59WzaE2/S+V
4AmPz5tg9g8tkWh3VrtCHDdD3rGPVZ4zEokJvif4etwHxCQQcS+aOGi3DCyzys+Y
qtytFxMzYOLjTbsWC/dqullgtEpNzbvdNB/EgFQjyAcPPL4SGM892R0O/o9wG0H+
ts6ttwdTDX+wXVy6h/uM4eK0gUrk85nOYaRSgmH4u9fGViNH27mkwCr234c3Dn6B
LmooeKnUXEU2vXxqetT0Yns72m2dsjpWBw/RVaZn7K9jW7/kIhPTZFA6boOWy3WD
NZ1BaMnQ7DcAOFuCi24W6dfl3f7wvj7tQF4fslW/vJ67wqd4N5E6h23ypx1E1Ahv
HwIDAQAB
-----END PUBLIC KEY-----

私人

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,DBA7527F283708D5

tTKAEnSBYtoHYwSxKS8j7dbeyKzUtemofRX4k/jYdj7ROCJqiA6QbxdK8qgEigVS
L83Ee/AK4m4JBC7kk+e8OTPdsohmlKYDSyjKiEhFniLUoN6I1Tc8NtZzyPgYLt6D
xKUKfLWhpRqR9UzJBaMMF6e4Eqm0dFv2oIfDBBXiyid+L+bakuHd2Mkm4pZnRywo
RQWrdAJx7vMv0tET2Zvfgt6S9EURwnoghd9kdtZ3a978Y207F9K2z5PNrA/MLW28
pz8Zf4+Usc0jjQ/DF3iEYKsGdLEsCBVbTf+1+8NMB7SftDAcnmCZes+2/mKfPT1k
w3pgQl3lmC8D1j1S6VfPd6voFfVxuGrf+hWAZQ3aLaqlnTm+0fl7ahD+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VKaFaYHs6anKN2yG4kZmaM7D/HuKoxBTRP0GTARZIEYSzPxkHURfWh
Cw+IMNJGWwPHMv/rrjoMhA4ucgIgd0GtfliiIIst+9J+shiPfxNK17B5Kx3wPgFY
BkQ52B1h0HmCNhEb4DJ2HRRKMky50cflaxNLEeUay+2/IJAsN9yb+g==
-----END RSA PRIVATE KEY-----

当我尝试使用以下过程加载密钥时,它总是在 Signatory1.LoadKeysFromStream(f, [partPrivate]);

When i try to load the key with the following procedure it always says "Stream reading Error" at line Signatory1.LoadKeysFromStream(f, [partPrivate]);

var
  f: TMemoryStream;
  Signatory1: TSignatory;
  codecRSA: TCodec;
  CryptographicLibrary1: TCryptographicLibrary;
  base64Ciphertext: string;
begin
   f:= TMemoryStream.Create;
   f.LoadFromFile('C:OpenSSL-Win32inprivate.pem');

  codecRSA :=TCodec.Create(nil);
  CryptographicLibrary1 := TCryptographicLibrary.Create(nil);
  Signatory1 :=TSignatory.Create(nil);

  //=============TCodec===================
  codecRSA.CryptoLibrary  := CryptographicLibrary1;
  codecRSA.StreamCipherId := 'native.RSA';
  codecRSA.ChainModeId:= 'native.CBC';
  codecRSA.AsymetricKeySizeInBits := 1024;

  //====Signatory1=====================
  Signatory1.Codec :=codecRSA;
  //===Load public key=============
  Signatory1.LoadKeysFromStream(f, [partPrivate]);
end;

有什么建议吗?我正在使用 Delphi XE7 和来自 Github 的最新版本的 Lockbox 3

Any suggestions? I am using Delphi XE7 and the latest release of Lockbox 3 from Github

推荐答案

根据我的经验,LockBox 3 在使用 OpenSSL 生成的密钥时需要一个 PKCS#1 公钥.您必须先将公钥转换为 PKCS#1,然后 Lockbox3 才能加载它.(OpenSSL 生成一个 PKCS#8 密钥).使用 RSAPublicKey 关键字.

In my experience, LockBox 3 needs a PKCS#1 public key when working with OpenSSL generated keys.You must convert the public key to PKCS#1 before Lockbox3 can load it. (OpenSSL generates a PKCS#8 key). Use the RSAPublicKey keyword.

openssl rsa -pubin -in yourpublickey -RSAPublicKey_out -out publicpkcs1

https://www.openssl.org/docs/apps/rsa.html

http://lockbox.seanbdurkin.id.au/tiki-view_forum_thread.php?comments_parentId=298&display=print

这篇关于密码箱 3 无法加载公钥 - 流读取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 06:48