0

I have the most basic Turbo LockBox 2 code that tries to load public RSA key that is generated with https://travistidwell.com/jsencrypt/demo/

Here is the unit:

unit MainFormU;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, LbCipher, LbClass, LbAsym, LbRSA,
  Vcl.StdCtrls;

type
  TMainForm = class(TForm)
    LbRSA: TLbRSA;
    LoadBtn: TButton;
    procedure LoadBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

const
  //skeypub=string('MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALPllOJsy3XNdicjBHT2MaxT7q74/vcKcWfZG4SBiJY0KGtbavsMpntgFPeqdQ4mDUEwpU6aWX7E3dXopRx9kXECAwEAAQ==');
skeypub=string(
'-----BEGIN PUBLIC KEY-----'+
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALPllOJsy3XNdicjBHT2MaxT7q74/vcK'+
'cWfZG4SBiJY0KGtbavsMpntgFPeqdQ4mDUEwpU6aWX7E3dXopRx9kXECAwEAAQ=='+
'-----END PUBLIC KEY-----');
  {
  skeyprv='MIIBOgIBAAJBALPllOJsy3XNdicjBHT2MaxT7q74/vcKcWfZG4SBiJY0KGtbavsM'+
    'pntgFPeqdQ4mDUEwpU6aWX7E3dXopRx9kXECAwEAAQJATvKtASVPsPYnKQvEE/RL'+
    'Xl5DPESH2DCcDkAIRIF4SLoCGHLu2cbi2YKpLJSNk34QdH4Vt1itadRIQu2SIs1G'+
    'AQIhAP2hKduEbtsZHgRDqMHYMEhKglbhbPaZ/AR3qg2oKbthAiEAtZQBILGWZGfB'+
    'GjB9Hn5RqcZxHpI4MbYjLxdb4AnMIBECIAzAcJlP1D8ByUePm0l7tBm+XUU++jp/'+
    'zXLwDUW4gbihAiEAsrA6A+B/rcNlBs7c8ltBJiBBReKDJnilWzxTj8BUfuECIBWY'+
    'nQUs9nKCzJAdoxmuTwH18odUlinGYGj2BNlPJ+dP'; }

procedure TMainForm.LoadBtnClick(Sender: TObject);
var S: TStringStream;
begin
  S:=TStringStream.Create(skeypub);
  LbRSA.PublicKey.LoadFromStream(S);
end;

end.

and here is the most basic component:

object LbRSA: TLbRSA
  PrimeTestIterations = 20
  KeySize = aks512
  Left = 184
  Top = 56
end

How to overcome 'Invalid RSA key' error message? Maybe my source code is not UTF8 formatted and that is why the skeypub string is not the valid Unicode string?

TomR
  • 2,696
  • 6
  • 34
  • 87
  • Are you sure you have used the same Key size? Default key size on the linked site seems to be 1024 bit but you are using 512 bit key size in your program. – SilverWarior Feb 11 '22 at 09:26
  • Yes, I put 512 on the site and then generated the keys. – TomR Feb 11 '22 at 09:46
  • 1
    Same issue here: `.LoadFromStream()` expects bytes, not ASCII fed through a `String`. Decode the Base64. No, it can't be a Unicode/UTF problem, since nothing in your code leaves the ASCII scope. – AmigoJack Feb 11 '22 at 18:17

0 Answers0