Reading PEM Private Key Using LockBox

I have to sign a digital string using the SHA-1 algorithm with RSA using the PKCS # 1 add-on. I downloaded Turbo Power Lockbox.

I have the private key in PEM format and was created using openssl:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj "/C=US/ST=CA/L=Mountain View/CN=www.mycompany.com" -keyout myrsakey.pem -out c:\temp\myrsacert.pem 

Here's what it looks like:

 -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDFzvqdAEQn9MrSLTNua5SOxshV/8jQIf3qpfunBXa9SVdm4NJw lY7iYpwivw7EdMlBe4FmezN9LGwyIokcUSt4KUdWmA8l4Lm5rcuDzzfmlVWP7y+j 0GKG2XCp2JwHpW4Q5WiMgcAnCMD/gbDustfz3utxQhLNBdWp2MlrEH2/rQIDAQAB AoGAUMZmnHohWtehgxYmLG8N6QfPgx7CWAupbop9KwUWKdGrOT2RcZwBDv0JmT6/ vwWZsX3Hp5ujuPfM7uQfbUrQHrcruUg/fPY8YXcWgNfOytGpaN/XKxfy2g2Cp8mE 4yoDR2QW8jo25ZH1q1cJ3jMyX9xlXaSZm7qtaoiDydE6roECQQDxqtP2tMEZ2FmQ 2o4T5Zv7P4II2PrLq+9IP0ASCZ2VzLxm2Pk6kxjnPjZ2oHG8pUQHvMz0m8Br3BY8 X1BpXrj9AkEA0YpBH7qm/nbG6YjxKAL3PbxXUJ06T/ByLjfstfCrT3LxDeklfWJb n/V8ahRcKPLajdbKAuWvJA5NvjeJPi34cQJAZ+vD1nUIDKsiaM3zBs9X8gTvUAqu XmMDNJguXxNPdplh8wAevHeA3/+6v+xivHJ8/K7Nm+pWJouv7Co4k/ctqQJASV4y TUzKmgC2xyCG5+6Z6Ujf/b7/ouva3un//PiG0yu40ZkX4l4lHM4UwQPd/QyDj/Rs CTWo7GQBvp+tc1MfUQJBALnQnNOIIkvwIK+1J6iLZgh7GurbCPMrH8nSn8SxkfBe qq5JWo31LQAUNDW5ntG0qHZQpx6zm2MzIlt2NgOLf4s= -----END RSA PRIVATE KEY----- 

If I'm not mistaken, the component I want to use is TLbRSAKey. So I tried to create a key object and read it from a file:

 var mPrivateKey: TLbRSAKey; begin mPrivateKey := TLbRSAKey.Create(aks1024); mPrivateKey.LoadFromFile('C:\temp\myrsakey.pem'); 

Error "Invalid RSA key" appears in LoadFromFile. What am I doing wrong? Does Lockbox support PEM keys? None of the examples illustrate; everything seems to be in ASN format

+2
source share
1 answer

I'm not a Delphi programmer, but I thought I'd try to provide some pointers.

First make sure that you create a new private key for your real application. Now that you have shared your private key with us, we do not need any open security holes.

Secondly, the ASN.1 format is generated using DER output from OpenSSL. The PEM format is just the base-64 encoding of the ASN.1 binary structure (and tokens are added).

You can return to DER in one of two ways:

1) . You can analyze and decode base 64 data in a PEM envelope. To do this, simply decode the data between the markers -----BEGIN/END RSA PRIVATE KEY----- .

Or, since you are still creating a new key ...;)

2) . You can use the -outform DER argument when creating your key using OpenSSL.

I'm not sure if this will work for your application, but maybe this will help you a little further.

TIP , to convert the PEM confirmation key to DER format, use the rsa utility in OpenSSL:

 openssl rsa -inform PEM -outform DER -in privkey.pem -out privkey.der 
+3
source

All Articles