Delphi LockBox3,Asymetric_Engine.createFromStream错误

时间:2016-07-12 09:15:25

标签: delphi rsa lockbox-3

编辑:因为我无法使用此代码,我做了一些解决方法:现在我通过ShellExecute调用openssl控制台(不太安全,但它有效)。

早上好,我很头疼让这个delphi代码工作:

(included uTPLb_* libraries)
function Crypto.encodeRSA(msg:String;test:Boolean = False):String;
  var
    file_path:String;
    keyStream:TMemoryStream;
    res:String;
    Codec:TCodec;
    wasAborted:Boolean;
    KeyPair:TAsymetricKeyPair;
    Key:TSymetricKey;
    lib:TCryptographicLibrary;
    signatory:TSignatory;
  begin
    codec:=TCodec.Create(nil);
    signatory:=TSignatory.Create(nil);
    lib:=TCryptoGraphicLibrary.Create(nil);
    try
     if test then
        begin
          file_path:=PUBLIC_KEY_TEST_FILE;
        end
      else
        begin
          file_path:=PUBLIC_KEY_FILE;
        end;
      file_path:=GetCurrentDir+'\'+file_path;
      keyStream:=TMemoryStream.Create;
      keyStream.LoadFromFile(file_path);

      codec.Reset;
      codec.CryptoLibrary:=lib;
      codec.ChainModeId:=ECB_ProgID;
      codec.StreamCipherId:='native.RSA';
      Codec.StreamCipherId:=RSA_ProgID;

      signatory.Codec:=codec;
      signatory.LoadKeysFromStream(keyStream,[partPublic]);


      //stuff to do...
      Result:=res;

    finally
      lib.Free;
      codec.Free;
    end;
  end;

问题是“signatory.LoadKeysFromStream(keyStream,[partPublic]);”程序继续失败,出现“Stream Error”异常;文件在阅读模式下正确打开。

公钥文件的内容是

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsU4LA0ZLWO+twuoReM41
...
-----END PUBLIC KEY-----

(我有全密钥,但我不喜欢泄露)

有人可以帮助我吗? 我读到了pkcs#1 padding和openssl命令 (Lockbox 3 load public key not possible - stream reading error

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

但无法识别“-RSAPublicKey_out”(OpenSSL 0.9.8zh 2016年1月14日)。 我也有私钥。

感谢所有可以帮助我的人!

更新: 我也尝试生成加密密钥,但我无法读取它们。

signatory.storeKeysToStream

结果是一样的。

我在这里下载了库: https://github.com/TurboPack/LockBox

0 个答案:

没有答案