#1 2024-04-18 06:32:33

Bjarne
Member
Registered: 2024-04-16
Posts: 4

Using keys generated by puttygen in TRsaPss

Hi.

I'm having trouble loading a public key - generated by PuttyGen.
Can anyone guide me in how to succeed?

Here is a few lines of code I've tried.

--- code ---

var
  lRsa : TRsaPss;
  lPublicKeyPEMString : string;
begin
  lRsa := TRsaPss.Create;
  try
    lPublicKeyPEMString := TFile.ReadAllText('RSA-3072-public-16042024.key');
    if lRsa.LoadFromPublicKeyPem(lPublicKeyPEMString) then
    begin
      <here I need to validate data earlier signed with TRsaPss.Sign - which can load and use the private key>
    end;
  finally
    lRsa.Free;
  end;
end;

---- code end ---

But no matter how I try to load the public key - it always returns false.
Do I use TRsaPss wrong?
I've also tried generating self-signed keys from various sites that provides this. But no matter how I try to load the public key - it always fails and returns false.

Any help is much appreciated.
/Bjarne

Offline

#2 2024-04-18 08:08:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using keys generated by puttygen in TRsaPss

Are you sure you are not making a confusion between a RSA key and a X509 certificate?

There is no such thing as a self-signed RSA key, there are X.509 self-signed certificates with a RSA key.

A RSA key is just a huge number.
A X509 certificate is what we use for TLS: it is a public (RSA) key with some fields, and a signature.

If not, last time I checked, PuttyGen does not generate PEM files, but its own base-64 encoded format.
And don't use a plain "string" type but rather "RawUtf8" or "Utf8String".

Offline

#3 2024-04-18 08:27:07

Bjarne
Member
Registered: 2024-04-16
Posts: 4

Re: Using keys generated by puttygen in TRsaPss

Hi ab.

I have the public key in a file - and the content is this

---- BEGIN SSH2 PUBLIC KEY ----
Comment: ""
AAAAB3NzaC1yc2EAAAADAQABAAABgQCo8VuO+2s3EucZzxqFqXjVJMEz7SJXNDe3
EWFKG8h3L8HZ9ZVssqOcl+f5tpUtw4aTelOScVODCLAWIpekregZeFXCwqEwncf5
Ys9DYHwqRQKCwaj9+PWsvBVhs4lNlZIHBfsvUZhbNhwNbEDLkJLC2eCzHEPrHc7r
w2NhafATQLyXkMUNpGwOJpJrkaxO62ErFV5Tpy1ZcX/oaPW2/lmupCuM+sVeslHO
L7mebAwnm3a2HbchxZ6eGsy9TwV+9V91vbmbi1pHRz6ZAw2+l0oc4jHhorbSaUQl
AevedIYjEad+COhMODULO2SW00owvQJta1IQK23fp4OG1/sRiS5bk+Tizjq8WQxc
rTLaV3wjlwVR6rbzzLGT0P3h8wgR8wEr5nsRq3HrqN0lXeNLOdwOYjpulXTCJBu6
eDCOE9MQf4YCxu6f1tucWnVf/bVruDY653JB0+fQ0xw3qSQfxPp1Of89kcAP7mgk
yCuTSLF2j2nsty59ixT2g+N5OJlzibE=
---- END SSH2 PUBLIC KEY ----

No matter if I use it as a string or load it from file. I cannot get lRsa.LoadFromPublicKeyPem to actually load the key.

Hope this explains it better.
/Bjarne

Offline

#4 2024-04-18 08:34:30

Bjarne
Member
Registered: 2024-04-16
Posts: 4

Re: Using keys generated by puttygen in TRsaPss

ab wrote:

There is no such thing as a self-signed RSA key, there are X.509 self-signed certificates with a RSA key.

Thanks for explaining that to me wink

ab wrote:

If not, last time I checked, PuttyGen does not generate PEM files, but its own base-64 encoded format.

In Putty I have used menu Conversions - Export OpenSSH Key - but I guess it only exports the private key.
But then again - I have not problems using the private key for signing my data.

/Bjarne

Offline

#5 2024-04-18 11:54:32

Bjarne
Member
Registered: 2024-04-16
Posts: 4

Re: Using keys generated by puttygen in TRsaPss

[SOLVED]
I have solved my problem.

BIG thanks to ab for taking time to question my "path" to my goal.

What I've learned is that.

Puttygen does not generate a readable public key part. hmm
Atleast not for me - in this situation.

After I got my hands on the certificate - and password. I could split it into private and public pem files.
These files loads perfectly with mORMot - TRsaPss.

So I've now accomplished my mission to sign data with use of the private key.
And be able to verify the data with use of the public key.

/Bjarne

Offline

Board footer

Powered by FluxBB