С помощью ChatGPT я придумал этот код, но он не работает должным образом, я получаю исключение:
Код: Выделить всё
System.Security.Cryptography.CryptographicException: ASN1 corrupted data.
---> System.Formats.Asn1.AsnContentException: The provided data is tagged with 'Universal' class value '16', but it should have been 'Universal' class value '2'.
Код: Выделить всё
public async Task ConvertToPfx(string certFilePath, string keyFilePath, string password)
{
byte[] certData = await File.ReadAllBytesAsync(certFilePath);
var certificate = new X509Certificate2(certData);
byte[] keyData = await File.ReadAllBytesAsync(keyFilePath);
RSA rsa = RSA.Create();
rsa.ImportRSAPrivateKey(keyData, out _); //
Подробнее здесь: [url]https://stackoverflow.com/questions/78751740/asn1-corrupted-data-exception-when-converting-cer-and-key-files-to-pfx-in-c-s[/url]