How to obtain private RSA key(private) as byte array in pgp file?

1.5k views Asked by At

I know that

gpg --export-secret-keys KEY_NAME > KEY_FILE

prints the key to file in pgp format. But what I need is to obtain the 2048 byte RSA key as byte array.

Why I need that? I am trying to convert a signing struture that uses RSA key from file that contains the keys as byte arrays. Something like.

bac6388....

I want to use my pgp key in this format first. Then I will start to use pgp keys.

When I run

 gpg --export-secret-keys KEY_NAME | xxd -p

it prints out what I want as below.

 9503be04556716da010800c92a2dee0cd36694c3337b9845d9d3653d9f02
 8398ebbfdc054657df710ab9d44cdd8bcfe9ea182dd257a629bd3d7ca045
 9878b7384b265f5967117ea314b1b1a3a6e376115de26cd90d59327920b5
 4af9022e1d60ec82.............

What I need is just the 2048 bit (256 byte) RSA key in this array. Also openssh(pem,crt) or openssl formats or even C/C++ is welcomed since I can translate the key to these formats.

I just want to get private key as byte array.

Thanks

2

There are 2 answers

0
ataman On BEST ANSWER

Hi here is the solution(on Ubnuntu)

First be sure that you removed the password of your key

 gpg --edit-key KEY_NAME

Write passwd on gpg consoler and press ENTER two times for new password.

Then gpg --export-secret-keys KEY_NAME > KEY_FILE

You need to install pgpdump

 sudo apt-get install pgpdump

Run

pgpdump -i -p KEY_FILE

Dumps all components of RSA key.

0
Cslayer20 On