0

I've generated a PKCS#1 RSA keypair using a program I wrote. I've output public key as DER encoding of the RSAPublicKey ASN.1 SEQUENCE data structure.

However, when I try to use it in the OpenSSL pkeyutl and rsautl commands, OpenSSL says

unable to load Public Key

I've tried both DER and PEM formats.

Is there additional encoding and/or data structure that I must apply for it to be usable in OpenSSL?

Here's my command line:

openssl pkeyutl -encrypt -pubin -in 128-bit.dat -inkey rsa-1440-pub.pem
openssl rsautl -in 128-bit.dat -encrypt -keyform PEM -pubin -inkey rsa-1440-pub.pem

The public key data structure in PEM format

-----BEGIN RSA PUBLIC KEY-----
MIG9AoG1AMuWjPN12DBObfQCxRVKLnP51BbFyEZeSJrmU3bPnwMv8S7hz0dGcSCA
Wa/EZWbNx8gLiWkHlcXeHC+8UO4rtOuaE9PhOXM819C8Y84Y8SddQ4RUMmj1y8ph
pBwExHDiSuKmbvFQLcB7uG10ZUFA9Q5bq/o6bNGsbTas/oB8TzSox5w66maDeyMc
cQFRko2/4AduuStYpnvi8eXa6kaAVDQ43NPCcdep0p78SKjYJNKu8WyZvwIDAQAB
-----END RSA PUBLIC KEY-----

1 Answer 1

0

For a public key to be accepted by OpenSSL, it appears that you need to wrap it in a SubjectPublicKeyInfo data structure. Like this:

-----BEGIN PUBLIC KEY-----
MIHTMA0GCSqGSIb3DQEBAQUAA4HBADCBvQKBtQDLlozzddgwTm30AsUVSi5z+dQW
xchGXkia5lN2z58DL/Eu4c9HRnEggFmvxGVmzcfIC4lpB5XF3hwvvFDuK7TrmhPT
4TlzPNfQvGPOGPEnXUOEVDJo9cvKYaQcBMRw4kripm7xUC3Ae7htdGVBQPUOW6v6
OmzRrG02rP6AfE80qMecOupmg3sjHHEBUZKNv+AHbrkrWKZ74vHl2upGgFQ0ONzT
wnHXqdKe/Eio2CTSrvFsmb8CAwEAAQ==
-----END PUBLIC KEY-----
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.