Re: Re: SonarLint complaining about "Use a stronger padding scheme"
Frank Sapone <[email protected]> Tue, 16 Apr 2024 18:01:21 -0700 (PDT)
| Newsgroups | gmane.comp.encryption.cryptopp |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_1632_1680274819.1713315681274
Content-Type: multipart/alternative;
boundary="----=_Part_1633_440046793.1713315681274"
------=_Part_1633_440046793.1713315681274
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
This code will be good for encoding a message... but I would like to=20
generate an X509 certificate with RSA PSS with SHA256 and have CryptoPP=20
load, then verify this certificate. Is this possible to do?
Thanks,
Frank
On Tuesday, April 16, 2024 at 7:48:45=E2=80=AFPM UTC-4 One Sini wrote:
> the code=20
>
> #include <iostream>=20
> #include <cryptopp/rsa.h>=20
> #include <cryptopp/filters.h>=20
> #include <cryptopp/osrng.h>=20
> #include <cryptopp/sha.h>=20
> #include <cryptopp/hex.h>=20
>
> int main() {
> // Generate RSA keys with 2048 bits=20
> CryptoPP::AutoSeededRandomPool rng;=20
> CryptoPP::RSA::PrivateKey =20
> privateKey; privateKey.GenerateRandomWithKeySize(rng, 2048);=20
>
> CryptoPP::RSA::PublicKey publicKey;=20
> publicKey.AssignFrom(privateKey);=20
>
> // Message=20
> std::string message =3D "secret";=20
>
> // Encrypt with OAEP padding=20
> CryptoPP::RSAES_OAEP_SHA_Encryptor encryptor(publicKey);=20
> std::string encrypted;=20
>
> CryptoPP::StringSource(message, true,=20
> new CryptoPP::PK_EncryptorFilter(rng, encryptor,=20
> new CryptoPP::StringSink(encrypted)=20
> )
> );=20
>
> // Decrypt=20
> CryptoPP::RSAES_OAEP_SHA_Decryptor decryptor(privateKey);=20
> std::string decrypted;=20
>
> CryptoPP::StringSource(encrypted, true,=20
> new CryptoPP::PK_DecryptorFilter(rng, decryptor,=20
> new CryptoPP::StringSink(decrypted)
> )=20
> );
>
> // Print results=20
> std::cout << "Original message: " << message << std::endl;=20
> std::cout << "Encrypted message (hex): ";=20
>
> CryptoPP::StringSource(encrypted, true,=20
> new CryptoPP::HexEncoder(=20
> new CryptoPP::FileSink(std::cout)
> )=20
> );=20
>
> std::cout << std::endl;=20
> std::cout << "Decrypted message: " << decrypted << std::endl;=20
>
> return 0;
> }
>
>
> Jeffrey Walton <[email protected]> schrieb am Di. 16. Apr. 2024 um 21:19:
>
>>
>>
>> On Tue, Apr 16, 2024 at 1:44=E2=80=AFPM One Sini <[email protected]> wrot=
e:
>>
>>> I wasn't entirely satisfied with the security, so I've adjusted the=20
>>> code. I'm not sure if that helps you, depending on what you're doing wi=
th=20
>>> it.
>>>
>>> This code uses RSA with OAEP (Optimal Asymmetric Encryption Padding) to=
=20
>>> avoid security issues like padding oracle attacks. It generates RSA key=
s=20
>>> with a length of 2048 bits, encrypts the message with OAEP padding, and=
=20
>>> then decrypts it.
>>>
>>> Best Regards Satoshi=20
>>>
>>
>> I deleted the message from the group. The *.pdf and *.pages smells of=20
>> malware.
>>
>> If you want to provide code, please inline it or provide it as a text=20
>> attachment.
>>
>> Jeff
>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "Crypto++ Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to [email protected].
>> To view this discussion on the web visit=20
>> https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8%3DwptAsfC1eM0Up=
37oZt14dok_C3R%3DqLiwSrbUJHiVNSw%40mail.gmail.com=20
>> <https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8%3DwptAsfC1eM0U=
p37oZt14dok_C3R%3DqLiwSrbUJHiVNSw%40mail.gmail.com?utm_medium=3Demail&utm_s=
ource=3Dfooter>
>> .
>>
>
--=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/d33c222f-a662-4676-9ce4-0223c9963897n%40googlegroups.com.
------=_Part_1633_440046793.1713315681274
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
This code will be good for encoding a message... but I would like to genera=
te an X509 certificate with RSA PSS with SHA256 and have CryptoPP load, the=
n verify this certificate.=C2=A0 Is this possible to do?<div><br /></div><d=
iv>Thanks,<br />Frank<br /><br /></div><div class=3D"gmail_quote"><div dir=
=3D"auto" class=3D"gmail_attr">On Tuesday, April 16, 2024 at 7:48:45=E2=80=
=AFPM UTC-4 One Sini wrote:<br/></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0 0 0 0.8ex; border-left: 1px solid rgb(204, 204, 204); paddi=
ng-left: 1ex;"><div dir=3D"auto">the code=C2=A0</div><div dir=3D"auto"><br>=
</div><div>#include <iostream>=C2=A0</div><div dir=3D"auto">#include =
<cryptopp/rsa.h>=C2=A0</div><div dir=3D"auto">#include <cryptopp/f=
ilters.h>=C2=A0</div><div dir=3D"auto">#include <cryptopp/osrng.h>=
=C2=A0</div><div dir=3D"auto">#include <cryptopp/sha.h>=C2=A0</div><d=
iv dir=3D"auto">#include <cryptopp/hex.h>=C2=A0</div><div dir=3D"auto=
"><br></div><div dir=3D"auto">int main() {<br></div><div dir=3D"auto">=C2=
=A0 =C2=A0 // Generate RSA keys with 2048 bits=C2=A0</div><div dir=3D"auto"=
>=C2=A0 =C2=A0 CryptoPP::AutoSeededRandomPool rng;=C2=A0</div><div dir=3D"a=
uto">=C2=A0 =C2=A0 CryptoPP::RSA::PrivateKey =C2=A0</div><div dir=3D"auto">=
=C2=A0 =C2=A0 privateKey; privateKey.GenerateRandomWithKeySize(rng, 2048);=
=C2=A0</div><div dir=3D"auto"><br></div><div dir=3D"auto">=C2=A0 =C2=A0 Cry=
ptoPP::RSA::PublicKey publicKey;=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0=
publicKey.AssignFrom(privateKey);=C2=A0</div><div dir=3D"auto"><br></div><=
div dir=3D"auto">=C2=A0 =C2=A0 // Message=C2=A0</div><div dir=3D"auto">=C2=
=A0 =C2=A0 std::string message =3D "secret";=C2=A0</div><div dir=
=3D"auto"><br></div><div dir=3D"auto">=C2=A0 =C2=A0// Encrypt with OAEP pad=
ding=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0CryptoPP::RSAES_OAEP_SHA_Enc=
ryptor encryptor(publicKey);=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0std:=
:string encrypted;=C2=A0</div><div dir=3D"auto"><br></div><div dir=3D"auto"=
>=C2=A0 =C2=A0CryptoPP::StringSource(message, true,=C2=A0</div><div dir=3D"=
auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0new CryptoPP::PK_EncryptorFilter(rng, encr=
yptor,=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 new CryptoPP::StringSink(encrypted)=C2=A0</div><div dir=3D"auto">=C2=A0=
=C2=A0 =C2=A0 =C2=A0)</div><div dir=3D"auto">=C2=A0);=C2=A0</div><div dir=
=3D"auto"><br></div><div dir=3D"auto">=C2=A0 =C2=A0 // Decrypt=C2=A0</div><=
div dir=3D"auto">=C2=A0 =C2=A0 CryptoPP::RSAES_OAEP_SHA_Decryptor decryptor=
(privateKey);=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0 std::string decryp=
ted;=C2=A0</div><div dir=3D"auto"><br></div><div dir=3D"auto">=C2=A0 =C2=A0=
CryptoPP::StringSource(encrypted, true,=C2=A0</div><div dir=3D"auto">=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 new CryptoPP::PK_DecryptorFilter(rng, decryptor,=
=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0new CryptoPP::StringSink(decrypted)</div><div dir=3D"auto">=C2=A0 =C2=A0=
=C2=A0 =C2=A0 )=C2=A0</div><div dir=3D"auto">=C2=A0);</div><div dir=3D"aut=
o"><br></div><div dir=3D"auto">=C2=A0 =C2=A0 // Print results=C2=A0</div><d=
iv dir=3D"auto">=C2=A0 =C2=A0 std::cout << "Original message: &q=
uot; << message << std::endl;=C2=A0</div><div dir=3D"auto">=C2=
=A0 =C2=A0 std::cout << "Encrypted message (hex): ";=C2=A0<=
/div><div dir=3D"auto"><br></div><div dir=3D"auto">=C2=A0 =C2=A0 CryptoPP::=
StringSource(encrypted, true,=C2=A0</div><div dir=3D"auto">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 new CryptoPP::HexEncoder(=C2=A0</div><div dir=3D"auto">=C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 new CryptoPP::FileSink(std::cout)</div>=
<div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 )=C2=A0</div><div dir=3D"auto=
">=C2=A0);=C2=A0</div><div dir=3D"auto"><br></div><div dir=3D"auto">=C2=A0 =
=C2=A0 std::cout << std::endl;=C2=A0</div><div dir=3D"auto">=C2=A0 =
=C2=A0 std::cout << "Decrypted message: " << decrypte=
d << std::endl;=C2=A0</div><div dir=3D"auto"><br></div><div dir=3D"au=
to">=C2=A0 =C2=A0 =C2=A0return 0;</div><div dir=3D"auto">=C2=A0}<br></div><=
div><br></div><div><br><div class=3D"gmail_quote"></div></div><div><div cla=
ss=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">Jeffrey Walton <=
;<a href data-email-masked rel=3D"nofollow">[email protected]</a>> schri=
eb am Di. 16. Apr. 2024 um 21:19:<br></div></div></div><div><div class=3D"g=
mail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-=
left-color:rgb(204,204,204)"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><b=
r><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, =
Apr 16, 2024 at 1:44=E2=80=AFPM One Sini <<a href data-email-masked rel=
=3D"nofollow">[email protected]</a>> wrote:<br></div><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;borde=
r-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><di=
v dir=3D"auto"><div><span style=3D"font-family:s=C3=B6hne,ui-sans-serif,sys=
tem-ui,-apple-system,"segoe ui",roboto,ubuntu,cantarell,"not=
o sans",sans-serif,"helvetica neue",arial,"apple color =
emoji","segoe ui emoji","segoe ui symbol","no=
to color emoji";font-size:16px;font-style:normal;font-weight:400;lette=
r-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;w=
ord-spacing:0px;text-decoration:none;float:none;display:inline;color:rgb(13=
,13,13)">I wasn't entirely satisfied with the security, so I've adj=
usted the code. I'm not sure if that helps you, depending on what you&#=
39;re doing with it.</span></div><br></div><div dir=3D"auto"><div><span sty=
le=3D"font-family:s=C3=B6hne,ui-sans-serif,system-ui,-apple-system,"se=
goe ui",roboto,ubuntu,cantarell,"noto sans",sans-serif,"=
;helvetica neue",arial,"apple color emoji","segoe ui em=
oji","segoe ui symbol","noto color emoji";font-siz=
e:16px;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:=
0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decorati=
on:none;float:none;display:inline;color:rgb(13,13,13)">This code uses RSA w=
ith OAEP (Optimal Asymmetric Encryption Padding) to avoid security issues l=
ike padding oracle attacks. It generates RSA keys with a length of 2048 bit=
s, encrypts the message with OAEP padding, and then decrypts it.</span></di=
v><div dir=3D"auto"><span style=3D"font-family:s=C3=B6hne,ui-sans-serif,sys=
tem-ui,-apple-system,"segoe ui",roboto,ubuntu,cantarell,"not=
o sans",sans-serif,"helvetica neue",arial,"apple color =
emoji","segoe ui emoji","segoe ui symbol","no=
to color emoji";font-size:16px;font-style:normal;font-weight:400;lette=
r-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;w=
ord-spacing:0px;text-decoration:none;float:none;display:inline;color:rgb(13=
,13,13)"><br></span></div><div dir=3D"auto"><span style=3D"font-family:s=C3=
=B6hne,ui-sans-serif,system-ui,-apple-system,"segoe ui",roboto,ub=
untu,cantarell,"noto sans",sans-serif,"helvetica neue",=
arial,"apple color emoji","segoe ui emoji","segoe =
ui symbol","noto color emoji";font-size:16px;font-style:norm=
al;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:non=
e;white-space:pre-wrap;word-spacing:0px;text-decoration:none;float:none;dis=
play:inline;color:rgb(13,13,13)">Best Regards Satoshi </span></div></div></=
blockquote><div><br></div><div>I deleted the message from the group. The *.=
pdf and *.pages smells of malware.</div><div><br></div><div>If you want to =
provide code, please inline it or provide it as a text attachment.<br></div=
><div><br></div><div>Jeff</div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;paddi=
ng-left:1ex;border-left-color:rgb(204,204,204)"><div><div class=3D"gmail_qu=
ote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-co=
lor:rgb(204,204,204)">
</blockquote></div></div></blockquote></div></div>
<p></p></blockquote></div></div><div><div class=3D"gmail_quote"><blockquote=
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:=
1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,=
204)">
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;Crypto++ Users" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href data-email-masked rel=3D"nofollow">cryptopp-user...@googleg=
roups.com</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/cryptopp-users/CAH8yC8%3DwptAsfC1eM0Up37oZt14dok_C3R%3DqLiwSrbUJ=
HiVNSw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter" target=
=3D"_blank" rel=3D"nofollow" data-saferedirecturl=3D"https://www.google.com=
/url?hl=3Den-US&q=3Dhttps://groups.google.com/d/msgid/cryptopp-users/CA=
H8yC8%253DwptAsfC1eM0Up37oZt14dok_C3R%253DqLiwSrbUJHiVNSw%2540mail.gmail.co=
m?utm_medium%3Demail%26utm_source%3Dfooter&source=3Dgmail&ust=3D171=
3401961479000&usg=3DAOvVaw0Qf6ChmDta2dQyP0E7Ole8">https://groups.google=
.com/d/msgid/cryptopp-users/CAH8yC8%3DwptAsfC1eM0Up37oZt14dok_C3R%3DqLiwSrb=
UJHiVNSw%40mail.gmail.com</a>.<br>
</blockquote></div></div>
</blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Crypto++ Users" 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/d33c222f-a662-4676-9ce4-0223c9963897n%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d=
/msgid/cryptopp-users/d33c222f-a662-4676-9ce4-0223c9963897n%40googlegroups.=
com</a>.<br />
------=_Part_1633_440046793.1713315681274--
------=_Part_1632_1680274819.1713315681274--