本文整理汇总了C#中X509Certificate2.GetECDsaPrivateKey方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2.GetECDsaPrivateKey方法的具体用法?C# X509Certificate2.GetECDsaPrivateKey怎么用?C# X509Certificate2.GetECDsaPrivateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X509Certificate2
的用法示例。
在下文中一共展示了X509Certificate2.GetECDsaPrivateKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadECDsaPrivateKey_OpenSslPfx
public static void ReadECDsaPrivateKey_OpenSslPfx()
{
using (var cert = new X509Certificate2(TestData.ECDsaP256_DigitalSignature_Pfx_OpenSsl, "Test"))
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
Assert.NotNull(ecdsa);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// If Windows were to start detecting this case as ECDSA that wouldn't be bad,
// but this assert is the only proof that this certificate was made with OpenSSL.
//
// Windows ECDSA PFX files contain metadata in the private key keybag which identify it
// to Windows as ECDSA. OpenSSL doesn't have anywhere to persist that data when
// extracting it to the key PEM file, and so no longer has it when putting the PFX
// together. But, it also wouldn't have had the Windows-specific metadata when the
// key was generated on the OpenSSL side in the first place.
//
// So, again, it's not important that Windows "mis-detects" this as ECDH. What's
// important is that we were able to create an ECDsa object from it.
AssertEccAlgorithm(ecdsa, "ECDH_P256");
}
}
}
示例2: ReadECDsaPrivateKey_WindowsPfx
public static void ReadECDsaPrivateKey_WindowsPfx()
{
using (var cert = new X509Certificate2(TestData.ECDsaP256_DigitalSignature_Pfx_Windows, "Test"))
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
Assert.NotNull(ecdsa);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
AssertEccAlgorithm(ecdsa, "ECDSA_P256");
}
}
}
示例3: ReadECDsaPrivateKey_BrainpoolP160r1_Pfx
public static void ReadECDsaPrivateKey_BrainpoolP160r1_Pfx(byte[] pfxData)
{
try
{
using (var cert = new X509Certificate2(pfxData, TestData.PfxDataPassword))
{
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
Assert.NotNull(ecdsa);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
AssertEccAlgorithm(ecdsa, "ECDH");
}
}
}
}
catch (CryptographicException)
{
// Windows 7, Windows 8, Ubuntu 14, CentOS can fail. Verify known good platforms don't fail.
Assert.False(PlatformDetection.IsWindows && PlatformDetection.WindowsVersion >= 10);
Assert.False(PlatformDetection.IsUbuntu1604);
Assert.False(PlatformDetection.IsOSX);
return;
}
}
示例4: ReadECDsaPrivateKey_WindowsPfx
public static void ReadECDsaPrivateKey_WindowsPfx(X509KeyStorageFlags keyStorageFlags)
{
using (var cert = new X509Certificate2(TestData.ECDsaP256_DigitalSignature_Pfx_Windows, "Test", keyStorageFlags))
{
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
Verify_ECDsaPrivateKey_WindowsPfx(ecdsa);
}
}
}