当前位置: 首页>>代码示例>>C#>>正文


C# Certificate.HasPrivateKey方法代码示例

本文整理汇总了C#中Certificate.HasPrivateKey方法的典型用法代码示例。如果您正苦于以下问题:C# Certificate.HasPrivateKey方法的具体用法?C# Certificate.HasPrivateKey怎么用?C# Certificate.HasPrivateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Certificate的用法示例。


在下文中一共展示了Certificate.HasPrivateKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DisplayCertificate


//.........这里部分代码省略.........
                else
                {
                    Console.WriteLine( "Extended Key Usage: Not valid for any usage.");
                    Console.WriteLine( "  Critical = " + Certificate.ExtendedKeyUsage().IsCritical );
                }
            }
            else
            {
                Console.WriteLine( "Extended Key Usage: Not present (valid for all usages).");
            }
            Console.WriteLine();

            if (Certificate.Template().IsPresent)
            {
                Console.WriteLine( "Template:");
                Console.WriteLine( "  Critical = " + Certificate.Template().IsCritical);
                Console.WriteLine( "  Name     = " + Certificate.Template().Name);
                Console.WriteLine( "  OID      = " + Certificate.Template().OID.FriendlyName + "(" + Certificate.Template().OID.Value + ")");
                Console.WriteLine( "  Major    = " + Certificate.Template().MajorVersion);
                Console.WriteLine( "  Minor    = " + Certificate.Template().MinorVersion);
            }
            else
            {
                Console.WriteLine( "Template: Not present.");
            }
            Console.WriteLine();

            Console.WriteLine( "Public Key:");
            Console.WriteLine( "  Algorithm  = " + Certificate.PublicKey().Algorithm.FriendlyName + "(" + Certificate.PublicKey().Algorithm.Value + ")");
            Console.WriteLine( "  Length     = " + Certificate.PublicKey().Length + " bits");
            Console.WriteLine( "  Key blob   = " + Certificate.PublicKey().EncodedKey.Format(true));
            Console.WriteLine( "  Parameters = " + Certificate.PublicKey().EncodedParameters.Format(true));

            if (Certificate.HasPrivateKey())
            {
                Console.WriteLine( "Private Key:");
                Console.WriteLine( "  Container name   = " + Certificate.PrivateKey.ContainerName);
                //Don't display unique container name for hardware token because it may cause UI to be displayed.
                if (! Certificate.PrivateKey.IsHardwareDevice())
                {
                    Console.WriteLine( "  Unique name      = " + Certificate.PrivateKey.UniqueContainerName);
                }
                Console.WriteLine( "  Provider name    = " + Certificate.PrivateKey.ProviderName);
                Console.WriteLine(     "  Provider type    = " );
                if (Convert.ToInt32(Certificate.PrivateKey.ProviderType) > ProviderTypes.GetUpperBound(0))
                {
                    Console.WriteLine( ProviderTypes[0] + " (" + Convert.ToString(Certificate.PrivateKey.ProviderType) + ")");
                }
                else
                {
                    Console.WriteLine( ProviderTypes[Convert.ToInt32(Certificate.PrivateKey.ProviderType)] + " (" + Convert.ToString(Certificate.PrivateKey.ProviderType) + ")");
                }
                Console.WriteLine(     "  Key spec         = " );
                if (Convert.ToInt32(Certificate.PrivateKey.KeySpec) > KeySpecStrings.GetUpperBound(0))
                {
                    Console.WriteLine( KeySpecStrings[0] + " (" + Convert.ToString(Certificate.PrivateKey.KeySpec) + ")");
                }
                else
                {
                    Console.WriteLine( KeySpecStrings[Convert.ToInt32(Certificate.PrivateKey.KeySpec)] + " (" + Convert.ToString(Certificate.PrivateKey.KeySpec) + ")");
                }
                Console.WriteLine( "  Accessible       = " + Certificate.PrivateKey.IsAccessible());
                Console.WriteLine( "  Protected        = " + Certificate.PrivateKey.IsProtected());
                Console.WriteLine( "  Exportable       = " + Certificate.PrivateKey.IsExportable());
                Console.WriteLine( "  Removable        = " + Certificate.PrivateKey.IsRemovable());
                Console.WriteLine( "  Machine keyset   = " + Certificate.PrivateKey.IsMachineKeyset());
开发者ID:SatishSara,项目名称:zxlooong,代码行数:67,代码来源:storesh.cs


注:本文中的Certificate.HasPrivateKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。