Re: Encrypting RSA private key with passphrase

Claude Robitaille <[email protected]> Thu, 16 Nov 2023 07:35:47 -0800 (PST)
Newsgroups gmane.comp.encryption.cryptopp
Message-ID <[email protected]>
------=_Part_8042_1450172475.1700148947451
Content-Type: multipart/alternative; 
	boundary="----=_Part_8043_1690182976.1700148947451"

------=_Part_8043_1690182976.1700148947451
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Humm almost 20 years later and I have the same question. And the FAQ does=
=20
not have the answer.

Actually, my case is a little bit more specific. I need to unlock a private=
=20
key that was locked somewhere else, using openSSL. The key usage is for=20
decrypting and unwrapping.=20

On Friday, August 27, 2004 at 4:57:26=E2=80=AFp.m. UTC-4 Vadim Ismailov wro=
te:

> There's an example in the cryptest how to generate RSA keypair. Here it=
=20
> is:=20
>
> void GenerateRSAKey(
> unsigned int keyLength,
> const char *privFilename,
> const char *pubFilename,
> const char *seed)
> {
> RandomPool randPool;
> randPool.Put((byte *)seed, strlen(seed));
> RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
> HexEncoder privFile(new FileSink(privFilename));
> priv.DEREncode(privFile);
> privFile.MessageEnd();
>
> RSAES_OAEP_SHA_Encryptor pub(priv);
> HexEncoder pubFile(new FileSink(pubFilename));
> pub.DEREncode(pubFile);
> pubFile.MessageEnd();
> }
>
> However, in this example both private and public keys are written to
> the files. I need to add one more parameter to this function (conat
> char* passphrase) and encrypt the private key (using some symmetric
> algorithm) prior to saving it to the file. Thus, each time anybody
> will need to use this private key for signing or decryption, he will
> need to enter the passphrase first, in order to decrypt private key.
> PGP works this way.
>
> Could anybody help me with this, please? I'm not familiar with the
> library yet and it is kind of hard to figure out myself. OTOH I have
> some urgent project to finish which requires such functionality.
>
> Obviously enough usage of temporary files is unacceptable in this
> case. This will compromise security.
>
> Thanks,
> Vadim
>
> P.S. I believe that this should be added to FAQ.
>
>

--=20
You received this message because you are subscribed to the Google Groups "=
Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
cryptopp-users/76c3b490-b59c-4644-a9b6-ec712c05dc77n%40googlegroups.com.

------=_Part_8043_1690182976.1700148947451
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div>Humm almost 20 years later and I have the same question. And the FAQ d=
oes not have the answer.<br /></div><div><br /></div><div>Actually, my case=
 is a little bit more specific. I need to unlock a private key that was loc=
ked somewhere else, using openSSL. The key usage is for decrypting and unwr=
apping. <br /></div><br /><div class=3D"gmail_quote"><div dir=3D"auto" clas=
s=3D"gmail_attr">On Friday, August 27, 2004 at 4:57:26=E2=80=AFp.m. UTC-4 V=
adim Ismailov wrote:<br/></div><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0 0 0 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left=
: 1ex;">There&#39;s an example in the cryptest how to generate RSA keypair.=
 Here it is: <p>void GenerateRSAKey(<br>   unsigned int keyLength,<br>   co=
nst char *privFilename,<br>   const char *pubFilename,<br>   const char *se=
ed)<br>{<br>   RandomPool randPool;<br>   randPool.Put((byte *)seed, strlen=
(seed));<br>   RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);<br>   He=
xEncoder privFile(new FileSink(privFilename));<br>   priv.DEREncode(privFil=
e);<br>   privFile.MessageEnd();<p>   RSAES_OAEP_SHA_Encryptor pub(priv);<b=
r>   HexEncoder pubFile(new FileSink(pubFilename));<br>   pub.DEREncode(pub=
File);<br>   pubFile.MessageEnd();<br>}<p>However, in this example both pri=
vate and public keys are written to<br>the files. I need to add one more pa=
rameter to this function (conat<br>char* passphrase) and encrypt the privat=
e key (using some symmetric<br>algorithm) prior to saving it to the file. T=
hus, each time anybody<br>will need to use this private key for signing or =
decryption, he will<br>need to enter the passphrase first, in order to decr=
ypt private key.<br>PGP works this way.<p>Could anybody help me with this, =
please? I&#39;m not familiar with the<br>library yet and it is kind of hard=
 to figure out myself. OTOH I have<br>some urgent project to finish which r=
equires such functionality.<p>Obviously enough usage of temporary files is =
unacceptable in this<br>case. This will compromise security.<p>Thanks,<br>V=
adim<p>P.S. I believe that this should be added to FAQ.<p></p></p></p></p><=
/p></p></p></p></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Crypto++ Users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">cryp=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/cryptopp-users/76c3b490-b59c-4644-a9b6-ec712c05dc77n%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d=
/msgid/cryptopp-users/76c3b490-b59c-4644-a9b6-ec712c05dc77n%40googlegroups.=
com</a>.<br />

------=_Part_8043_1690182976.1700148947451--

------=_Part_8042_1450172475.1700148947451--