/// <summary>Extracts a <see cref="Key"/> from the given certificate.</summary> public Initializer FromCertificate(X509Certificate2 certificate) { #if NETSTANDARD Key = certificate.GetRSAPrivateKey(); #else // Workaround to correctly cast the private key as a RSACryptoServiceProvider type 24. RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)certificate.PrivateKey; byte[] privateKeyBlob = rsa.ExportCspBlob(true); Key = new RSACryptoServiceProvider(); Key.ImportCspBlob(privateKeyBlob); #endif return(this); }
/// <summary>Extracts a <see cref="Key"/> from the given certificate.</summary> public Initializer FromCertificate(X509Certificate2 certificate) { #if NETSTANDARD Key = certificate.GetRSAPrivateKey(); #else // Workaround to correctly cast the private key as a RSACryptoServiceProvider type 24. RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)certificate.PrivateKey; byte[] privateKeyBlob = rsa.ExportCspBlob(true); Key = new RSACryptoServiceProvider(); Key.ImportCspBlob(privateKeyBlob); #endif return this; }