internal static ECDsa MakeExportable(this ECDsa ecdsa) { if (ecdsa is ECDsaCng dsaCng) { const CngExportPolicies Exportability = CngExportPolicies.AllowExport | CngExportPolicies.AllowPlaintextExport; if ((dsaCng.Key.ExportPolicy & Exportability) == CngExportPolicies.AllowExport) { ECDsa copy = ECDsa.Create(); copy.ImportEncryptedPkcs8PrivateKey( nameof(MakeExportable), ecdsa.ExportEncryptedPkcs8PrivateKey( nameof(MakeExportable), new PbeParameters( PbeEncryptionAlgorithm.TripleDes3KeyPkcs12, HashAlgorithmName.SHA1, 2048)), out _); return(copy); } } return(ecdsa); }
private ECDsa getRootPrivateKey() { string keyFile = File.ReadAllText(_configuration["PrivateKeyPath"]); // extract base64 encoded private key Regex regex = new Regex(@"(-----BEGIN ENCRYPTED PRIVATE KEY-----)((.|\n)*)(-----END ENCRYPTED PRIVATE KEY-----)"); string keyBase64 = regex.Match(keyFile).Groups[2].ToString(); ECDsa eC = ECDsa.Create(); string pw = _configuration["PrivateKeyPw"]; // byte[] pwBytes = Encoding.UTF8.GetBytes(pw); eC.ImportEncryptedPkcs8PrivateKey(Encoding.UTF8.GetBytes(pw), Convert.FromBase64String(keyBase64), out _); return(eC); }