我用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+pDVvTHNJ
F9grzlo4mYlLzsbs8/eLcUjxfU8wuvL9aph6zeYt2YcQSyOhR3FqS2Er+dOyQVDM
AeBz8X/0hughzkjztvBbrfA5WmQ0h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NK17B5Kx3wPgFY
BkQ52B1h0HmCNhEb4DJ2HRRKMky50cflaxNLEeUay+2/IJAsN9yb+g==
-----END RSA PRIVATE KEY-----
当我尝试使用以下程序加载密钥时,它总是说"流读取错误"在Signatory1.LoadKeysFromStream(f, [partPrivate]);
行
var
f: TMemoryStream;
Signatory1: TSignatory;
codecRSA: TCodec;
CryptographicLibrary1: TCryptographicLibrary;
base64Ciphertext: string;
begin
f:= TMemoryStream.Create;
f.LoadFromFile('C:\OpenSSL-Win32\bin\private.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
答案 0 :(得分:3)
根据我的经验,在使用OpenSSL生成的密钥时,LockBox 3需要PKCS#1公钥。 在Lockbox3加载之前,您必须将公钥转换为PKCS#1。 (OpenSSL生成PKCS#8密钥)。使用RSAPublicKey关键字。
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
答案 1 :(得分:0)
加载流后,应将其重置为开头,然后再将其移交给LoadKeysFromStream。
//====Signatory1=====================
Signatory1.Codec :=codecRSA;
//===Load public key=============
f.Position := 0;
Signatory1.LoadKeysFromStream(f, [partPrivate]);