Am exportat certificatul CA rădăcină (ISRG Root X1) folosit de certificatul digital StackOverflow, ca fișier binar X.509 (.cer) codificat DER și am folosit openssl în cmd pentru a afla modulul/exponentul:
openssl.exe x509 -in C:\Cert.cer -inform der -text
Apoi am făcut același lucru pentru următorul certificat din lanț care se numește R3, pentru a obține semnătura:
Semnătura pentru R3:
Le-am copiat în C# ca matrice de octeți și folosesc următorul cod pentru a decripta semnătura:
folosind System.Security.Cryptography;
spațiu de nume RsaDecryptor
{
Programul clasei
{
static void Main(string[] args)
{
byte[] decryptedData;
folosind (RSACryptoServiceProvider rsa = nou RSACryptoServiceProvider())
{
var bytesRead = 0;
// De la rădăcina ISRG CA:
modul var = octet nou[] { 0xad, 0xe8, 0x24, 0x73, 0xf4, 0x14, 0x37, 0xf3, 0x9b, 0x9e, 0x2b, 0x57, 0x28, 0x1c,
0x87, 0xbe, 0xdc, 0xb7, 0xdf, 0x38, 0x90, 0x8c, 0x6e, 0x3c, 0xe6, 0x57, 0xa0, 0x78, 0xf7, 0x75, 0x2, 0x2,
0xfe, 0xf5, 0x6a, 0x6e, 0xf6, 0x00, 0x4f, 0x28, 0xdb, 0xde, 0x68, 0x86, 0x6c, 0x44, 0x93, 0xb6, 0xb1, 0xb6, 0x3
0xfd, 0x14, 0x12, 0x6b, 0xbf, 0x1f, 0xd2, 0xea, 0x31, 0x9b, 0x21, 0x7e, 0xd1, 0x33, 0x3c, 0xba, 0x48,, 0x48
0xdd, 0x79, 0xdf, 0xb3, 0xb8, 0xff, 0x12, 0xf1, 0x21, 0x9a, 0x4b, 0xc1, 0x8a, 0x86, 0x71, 0x69, 0x66a, 0x66a,
0x66, 0x6c, 0x8f, 0x7e, 0x3c, 0x70, 0xbf, 0xad, 0x29, 0x22, 0x06, 0xf3, 0xe4, 0xc0, 0xe6, 0x80, 0xae, 0x80, 0xae,
0x4b, 0x8f, 0xb7, 0x99, 0x7e, 0x94, 0x03, 0x9f, 0xd3, 0x47, 0x97, 0x7c, 0x99, 0x48, 0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 0x4e, 0xe6, 0xd9, 0x3b,,
0xc6, 0xdd, 0x27, 0x51, 0x6e, 0xff, 0xbc, 0x64, 0xf5, 0x33, 0x43, 0x4f};
// De la CA intermediar R3:
semnătură var = octet nou[] { 0x85, 0xca, 0x4e, 0x47, 0x3e, 0xa3, 0xf7, 0x85, 0x44, 0x85, 0xbc, 0xd5, 0x67, 0x78,
0xb2, 0x98, 0x63, 0xad, 0x75, 0x4d, 0x1e, 0x96, 0x3d, 0x33, 0x65, 0x72, 0x54, 0x2d, 0x81, 0xa0, 0cx3
0xed, 0xf8, 0x20, 0xbf, 0x5f, 0xcc, 0xb7, 0x70, 0x00, 0xb7, 0x6e, 0x3b, 0xf6, 0x5e, 0x94, 0xde, 0xe4,, 0xde, 0xe4
0x9f, 0xa6, 0xef, 0x8b, 0xb2, 0x03, 0xe7, 0xa2, 0xb5, 0x16, 0x3c, 0x91, 0xce, 0xb4, 0xed, 0x39, 0x02,
0x7c, 0x25, 0x8a, 0x47, 0xe6, 0x65, 0x6e, 0x3f, 0x46, 0xf4, 0xd9, 0xf0, 0xce, 0x94, 0x2b, 0xee, 0xce, 0xce,
0x12, 0xbc, 0x8c, 0x27, 0x4b, 0xb8, 0xc1, 0x98, 0x2f, 0xa2, 0xaf, 0xcd, 0x71, 0x91, 0x4a, 0x08, 0xc8, 0xc8
0xb8, 0x23, 0x7b, 0x04, 0x2d, 0x08, 0xf9, 0x08, 0x57, 0x3e, 0x83, 0xd9, 0x04, 0x33, 0x0a, 0x47, 0x47,,
0x09, 0x82, 0x27, 0xc3, 0x2a, 0xc8, 0x9b, 0xb9, 0xce, 0x5c, 0xf2, 0x64, 0xc8, 0xc0, 0xbe, 0x79, 0x79, 0xc0
0x8e, 0x6d, 0x44, 0x0c, 0x5e, 0x92, 0xbb, 0x2e, 0xf7, 0x8b, 0x10, 0xe1, 0xe8, 0x1d, 0x44, 0x29, 0x5b,, 0x59
0x20, 0xed, 0x63, 0xb9, 0x21, 0xf8, 0x12, 0x26, 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3, 0xda, 0xd70,
0x87, 0x6c, 0x84, 0x21, 0x31, 0xae, 0x82, 0xf5, 0xfb, 0xb9, 0xab, 0xc8, 0x89, 0x17, 0x3d, 0xe1, 0x4c, 0x4c
0x38, 0x0e, 0xf6, 0xbd, 0x2b, 0xbd, 0x96, 0x81, 0x14, 0xeb, 0xd5, 0xdb, 0x3d, 0x20, 0xa7, 0x7e, 0x59,, 0x59
0xe2, 0xf8, 0x58, 0xf9, 0x5b, 0xb8, 0x48, 0xcd, 0xfe, 0x5c, 0x4f, 0x16, 0x29, 0xfe, 0x1e, 0x55, 0x23,
0xc8, 0x11, 0xb0, 0x8d, 0xea, 0x7c, 0x93, 0x90, 0x17, 0x2f, 0xfd, 0xac, 0xa2, 0x09, 0x47, 0x46, 0x3f
0xe9, 0xb0, 0xb7, 0xff, 0x28, 0x4d, 0x68, 0x32, 0xd6, 0x67, 0x5e, 0x1e, 0x69, 0xa3, 0x93, 0xb8, 0x9d
0x8b, 0x2f, 0x0b, 0xd2, 0x52, 0x43, 0xa6, 0x6f, 0x32, 0x57, 0x65, 0x4d, 0x32, 0x81, 0xdf, 0x38, 0x38, 0x38, 0x4d
0x5d, 0x7e, 0x5d, 0x66, 0x29, 0xea, 0xb8, 0xdd, 0xe4, 0x95, 0xb5, 0xcd, 0xb5, 0x56, 0x12, 0x42, 0xc4, 0xc4
0x4e, 0xc6, 0x25, 0x38, 0x44, 0x50, 0x6d, 0xec, 0xce, 0x00, 0x55, 0x18, 0xfe, 0xe9, 0x49, 0x64, 0xd4,
0xca, 0x97, 0x9c, 0xb4, 0x5b, 0xc0, 0x73, 0xa8, 0xab, 0xb8, 0x47, 0xc2};
// Următoarea linie are ca rezultat:
// AsnContentException: lungimea codificată depășește valoarea maximă acceptată de această bibliotecă (Int32.MaxValue).
rsa.ImportRSAPublicKey(modul, out bytesRead);
//var rsaParams = RSAParameters noi();
//rsaParams.Modulus = modul;
//rsaParams.Exponent = octet nou[] { 0x01, 0x00, 0x01 };
//rsa.ImportParameters(rsaParams);
// Dacă se folosesc în schimb cele 4 rânduri de mai sus, următoarele aruncări:
// System.Security.Cryptography.CryptographicException: „Cryptography_OAEPDcoding”
// dacă fOAEP == adevărat.
// dacă fOAEP == false, atunci se aruncă:
// Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException: „Cheia nu există”.
var fOAEP = fals;
decryptedData = rsa.Decrypt(semnătură, fOAEP);
}
}
}
}
rsa.ImportRSAPublicKey(modul, out bytesRead);
eșuează cu:
System.Security.Cryptography.CryptographicException: „Date corupte ASN1”.
AsnContentException: lungimea codificată depășește valoarea maximă acceptată de această bibliotecă (Int32.MaxValue).
Din comentariile din codul de mai sus, puteți vedea că încerc o altă metodă, dar și aceasta eșuează.
Este acesta modul corect de a decripta manual o semnătură folosind RSA?
Trebuie să precizez undeva exponentul? Sau se presupune că este 65537?