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


C# X509Certificates.X500DistinguishedName类代码示例

本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X500DistinguishedName的典型用法代码示例。如果您正苦于以下问题:C# X500DistinguishedName类的具体用法?C# X500DistinguishedName怎么用?C# X500DistinguishedName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


X500DistinguishedName类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了X500DistinguishedName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCertificate

 public static X509Certificate2 CreateCertificate(X500DistinguishedName subjectName, string friendlyName)
 {
     var key = Create2048RsaKey();
     var cert = CreateSelfSignedCertificate(key, subjectName);
     cert.FriendlyName = friendlyName;
     return cert;
 }
开发者ID:suwatch,项目名称:AzureCLI,代码行数:7,代码来源:CertHelper.cs

示例2: ConvertDistinguishedNameToString

 public static string ConvertDistinguishedNameToString(X500DistinguishedName dnString)
 {
     string name = dnString.Name;
     bool flag = false;
     string[] strArray = dnString.Decode(X500DistinguishedNameFlags.UseNewLines).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
     if (strArray.Length > 0)
     {
         flag = true;
         string pairAndValue = string.Empty;
         for (int i = 0; i < strArray.Length; i++)
         {
             pairAndValue = strArray[i];
             Pair pair = ConvertStringToPair(pairAndValue);
             if (string.Equals((string) pair.First, "CN", StringComparison.OrdinalIgnoreCase))
             {
                 name = (string) pair.Second;
                 flag = false;
                 break;
             }
         }
     }
     else
     {
         name = (string) ConvertStringToPair(name).Second;
         flag = false;
     }
     if (flag)
     {
         name = dnString.Name;
     }
     return name;
 }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:32,代码来源:FtpHelper.cs

示例3: CreateSelfSignedCertificate

        private static X509Certificate2 CreateSelfSignedCertificate(CngKey key, X500DistinguishedName subjectName)
        {
            using (SafeCertContextHandle selfSignedCertHandle = CreateSelfSignedCertificate(key,
                                                                                            true,
                                                                                            subjectName.RawData,
                                                                                            X509CertificateCreationOptions.None, // NONE
                                                                                            RsaSha1Oid,
                                                                                            DateTime.UtcNow,
                                                                                            DateTime.UtcNow.AddYears(1)))
            {
                X509Certificate2 certificate = null;
                bool addedRef = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    selfSignedCertHandle.DangerousAddRef(ref addedRef);
                    certificate = new X509Certificate2(selfSignedCertHandle.DangerousGetHandle());
                }
                finally
                {
                    if (addedRef)
                    {
                        selfSignedCertHandle.DangerousRelease();
                    }
                }

                key.Dispose();

                return certificate;
            }
        }
开发者ID:bstearns,项目名称:VipSwapper,代码行数:31,代码来源:CertHelper.cs

示例4: SelfSignedCertProperties

 public SelfSignedCertProperties()
 {
     DateTime today = DateTime.Today;
     ValidFrom = today.AddDays(-1);
     ValidTo = today.AddYears(10);
     Name = new X500DistinguishedName("cn=self");
     KeyBitLength = 4096;
 }
开发者ID:sagar1589,项目名称:Delta.Cryptography,代码行数:8,代码来源:CertProperties.cs

示例5: CreateNewCertificate

        /// <summary>
        /// Create a RSA based certificate (to be used with encryption) with the given options
        /// </summary>
        /// <param name="buildOptions">Allows for more advanced configuration</param>
        /// <returns>An exportable X509Certificate2 object (with private key)</returns>
        public static X509Certificate2 CreateNewCertificate(RSACertificateBuilderOptions buildOptions)
        {
            if (buildOptions == null)
            {
                throw new ArgumentNullException("buildOptions");
            }

            string keyName = buildOptions.RSAKeyName ?? "RSAKey";

            CngKey objCngKey = null;
            if (CngKey.Exists(keyName))
            {
                objCngKey = CngKey.Open(keyName);
                objCngKey.Delete();
            }

            var creationParameters = new CngKeyCreationParameters();
            creationParameters.ExportPolicy = CngExportPolicies.AllowExport;
            creationParameters.KeyUsage = CngKeyUsages.AllUsages;
            creationParameters.Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider;
            var keySizeProperty = new CngProperty("Length", BitConverter.GetBytes(buildOptions.KeySize ?? 4096), CngPropertyOptions.None);
            creationParameters.Parameters.Add(keySizeProperty);

            objCngKey = CngKey.Create(CngAlgorithm2.Rsa, keyName, creationParameters);

            var name = new X500DistinguishedName(buildOptions.FullSubjectName);

            X509CertificateSignatureAlgorithm certAlg;
            switch (buildOptions.HashingMethod ?? HashingMethods.Sha256)
            {
                case HashingMethods.Sha1:
                    certAlg = X509CertificateSignatureAlgorithm.RsaSha1;
                    break;
                case HashingMethods.Sha256:
                    certAlg = X509CertificateSignatureAlgorithm.RsaSha256;
                    break;
                case HashingMethods.Sha384:
                    certAlg = X509CertificateSignatureAlgorithm.RsaSha384;
                    break;
                case HashingMethods.Sha512:
                    certAlg = X509CertificateSignatureAlgorithm.RsaSha512;
                    break;
                default:
                    throw new InvalidOperationException("Selected hashing method is not supported");
            }

            var options = new X509CertificateCreationParameters(name)
            {
                SignatureAlgorithm = certAlg,
                TakeOwnershipOfKey = true
            };

            return objCngKey.CreateSelfSignedCertificate(options);
        }
开发者ID:KalixHealth,项目名称:Kalix.ApiCrypto,代码行数:59,代码来源:RSACertificateBuilder.cs

示例6: X500DistinguishedName

		public X500DistinguishedName (X500DistinguishedName distinguishedName)
		{
			if (distinguishedName == null)
				throw new ArgumentNullException ("distinguishedName");

			Oid = new Oid ();
			RawData = distinguishedName.RawData;
			name = distinguishedName.name;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:9,代码来源:X500DistinguishedName.cs

示例7: CreateX500DistinguishedNameClaim

        public static Claim CreateX500DistinguishedNameClaim(X500DistinguishedName x500DistinguishedName)
        {
            if (x500DistinguishedName == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("x500DistinguishedName");

            return new Claim(ClaimTypes.X500DistinguishedName, x500DistinguishedName, Rights.PossessProperty, ClaimComparer.X500DistinguishedName);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:Claim.cs

示例8: X500DistinguishedNameClaimSet

            public X500DistinguishedNameClaimSet(X500DistinguishedName x500DistinguishedName)
            {
                if (x500DistinguishedName == null)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("x500DistinguishedName");

                _identity = new X509Identity(x500DistinguishedName);
                List<Claim> claims = new List<Claim>(2);
                claims.Add(new Claim(ClaimTypes.X500DistinguishedName, x500DistinguishedName, Rights.Identity));
                claims.Add(Claim.CreateX500DistinguishedNameClaim(x500DistinguishedName));
                Initialize(ClaimSet.Anonymous, claims);
            }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:11,代码来源:X509CertificateClaimSet.cs

示例9: FormatDistinguishedName

        private string FormatDistinguishedName(X500DistinguishedName dn)
        {
            var subjectName = dn.Name;
            if (subjectName.Contains("\""))
            {
                bool insideQuotes = false;
                string subjectName2 = string.Empty;
                for (int i = 0; i < subjectName.Length; i++)
                {
                    if (subjectName[i] == '"') insideQuotes = !insideQuotes;
                    if ((subjectName[i] == ',') && insideQuotes)
                        subjectName2 += '#';
                    else subjectName2 += subjectName[i];
                }

                subjectName = subjectName2;
            }

            var parts = subjectName.Split(',');
            var part = string.Empty;

            if (parts.Length == 0) part = dn.Name;
            else part = parts[0];

            part = part.Replace('#', ',');
            part = part.Replace("\"", string.Empty);

            int index = part.IndexOf('=');
            if (index != -1) part = part.Substring(index + 1);

            return part;
        }
开发者ID:sagar1589,项目名称:Delta.Cryptography,代码行数:32,代码来源:X509Object.cs

示例10: SubjectIdentifier

        internal unsafe SubjectIdentifier (CAPI.CRYPTOAPI_BLOB issuer, CAPI.CRYPTOAPI_BLOB serialNumber) {
            // If serial number is 0, then it is the special SKI encoding or NoSignature
            bool isSKIorHashOnly = true;
            byte * pb = (byte *) serialNumber.pbData;
            for (uint i = 0; i < serialNumber.cbData; i++) {
                if (*pb++ != (byte) 0) {
                    isSKIorHashOnly = false;
                    break;
                }
            }

            if (isSKIorHashOnly) {
                byte[] issuerBytes = new byte[issuer.cbData];
                Marshal.Copy(issuer.pbData, issuerBytes, 0, issuerBytes.Length);
                X500DistinguishedName dummyName = new X500DistinguishedName(issuerBytes);
                if (String.Compare(CAPI.DummySignerCommonName, dummyName.Name, StringComparison.OrdinalIgnoreCase) == 0) {
                    Reset(SubjectIdentifierType.NoSignature, null);
                    return;
                }
            }

            if (isSKIorHashOnly) {
                // Decode disguised SKI in issuer field (See WinCrypt.h for more info).  Note that some certificates may contain
                // an all-zero serial number but not be encoded with an szOID_KEYID_RDN.  In order to allow use of signatures created
                // using these certificates, we will first try to find the szOID_KEYID_RDN, but if it does not exist, fall back to just
                // decoding the incoming issuer and serial number.
                m_type = SubjectIdentifierType.SubjectKeyIdentifier;
                m_value = String.Empty;

                uint cbCertNameInfo = 0;
                SafeLocalAllocHandle pbCertNameInfo = SafeLocalAllocHandle.InvalidHandle;

                if (CAPI.DecodeObject(new IntPtr(CAPI.X509_NAME),
                                      issuer.pbData,
                                      issuer.cbData,
                                      out pbCertNameInfo,
                                      out cbCertNameInfo)) {
                    using (pbCertNameInfo) {
                        checked {
                            CAPI.CERT_NAME_INFO certNameInfo = (CAPI.CERT_NAME_INFO) Marshal.PtrToStructure(pbCertNameInfo.DangerousGetHandle(), typeof(CAPI.CERT_NAME_INFO));
                            for (uint i = 0; i < certNameInfo.cRDN; i++) {
                                CAPI.CERT_RDN certRdn = (CAPI.CERT_RDN) Marshal.PtrToStructure(new IntPtr((long) certNameInfo.rgRDN + (long) (i * Marshal.SizeOf(typeof(CAPI.CERT_RDN)))), typeof(CAPI.CERT_RDN));

                                for (uint j = 0; j < certRdn.cRDNAttr; j++)
                                {
                                    CAPI.CERT_RDN_ATTR certRdnAttr = (CAPI.CERT_RDN_ATTR)Marshal.PtrToStructure(new IntPtr((long)certRdn.rgRDNAttr + (long)(j * Marshal.SizeOf(typeof(CAPI.CERT_RDN_ATTR)))), typeof(CAPI.CERT_RDN_ATTR));

                                    if (String.Compare(CAPI.szOID_KEYID_RDN, certRdnAttr.pszObjId, StringComparison.OrdinalIgnoreCase) == 0)
                                    {
                                        if (certRdnAttr.dwValueType == CAPI.CERT_RDN_OCTET_STRING)
                                        {
                                            byte[] ski = new byte[certRdnAttr.Value.cbData];
                                            Marshal.Copy(certRdnAttr.Value.pbData, ski, 0, ski.Length);
                                            Reset(SubjectIdentifierType.SubjectKeyIdentifier, X509Utils.EncodeHexString(ski));
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            CAPI.CERT_ISSUER_SERIAL_NUMBER IssuerAndSerial;
            IssuerAndSerial.Issuer = issuer;
            IssuerAndSerial.SerialNumber = serialNumber;
            X509IssuerSerial issuerSerial = PkcsUtils.DecodeIssuerSerial(IssuerAndSerial);
            Reset(SubjectIdentifierType.IssuerAndSerialNumber, issuerSerial);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:70,代码来源:PkcsMisc.cs

示例11: Constructor_String_Flags_Reversed

		public void Constructor_String_Flags_Reversed ()
		{
			X500DistinguishedName dn = new X500DistinguishedName (name, X500DistinguishedNameFlags.None);
			// can't call RsaIssuer because Name is reversed from None in those cases
			Assert.AreEqual (name, dn.Name, "Name");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.None), "Decode(None)");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.Reversed), "Decode(Reversed)");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.DoNotUsePlusSign), "Decode(DoNotUsePlusSign)");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.UseCommas), "Decode(UseCommas)");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.UseUTF8Encoding), "Decode(UseUTF8Encoding)");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.UseT61Encoding), "Decode(UseT61Encoding)");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.ForceUTF8Encoding), "Decode(ForceUTF8Encoding)");
		}
开发者ID:blinds52,项目名称:mono,代码行数:13,代码来源:X500DistinguishedNameTest.cs

示例12: Constructor_String_Flags_None

		public void Constructor_String_Flags_None ()
		{
			X500DistinguishedName dn = new X500DistinguishedName (rname, X500DistinguishedNameFlags.None);
			// can't call RsaIssuer because Name is reversed from None in those cases
			// i.e. X500DistinguishedName (string) != X500DistinguishedName (string, X500DistinguishedNameFlags)
			Assert.AreEqual (rname, dn.Name, "Name");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.None), "Decode(None)");
			Assert.AreEqual (name, dn.Decode (X500DistinguishedNameFlags.Reversed), "Decode(Reversed)");
			Assert.AreEqual ("C=US; O=\"RSA Data Security, Inc.\"; OU=Secure Server Certification Authority", dn.Decode (X500DistinguishedNameFlags.UseSemicolons), "Decode(UseSemicolons)");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.DoNotUsePlusSign), "Decode(DoNotUsePlusSign)");
			Assert.AreEqual ("C=US, O=RSA Data Security, Inc., OU=Secure Server Certification Authority", dn.Decode (X500DistinguishedNameFlags.DoNotUseQuotes), "Decode(DoNotUseQuotes)");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.UseCommas), "Decode(UseCommas)");
			string newline = String.Format ("C=US{0}O=\"RSA Data Security, Inc.\"{0}OU=Secure Server Certification Authority", Environment.NewLine);
			Assert.AreEqual (newline, dn.Decode (X500DistinguishedNameFlags.UseNewLines), "Decode(UseNewLines)");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.UseUTF8Encoding), "Decode(UseUTF8Encoding)");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.UseT61Encoding), "Decode(UseT61Encoding)");
			Assert.AreEqual (rname, dn.Decode (X500DistinguishedNameFlags.ForceUTF8Encoding), "Decode(ForceUTF8Encoding)");
		}
开发者ID:blinds52,项目名称:mono,代码行数:18,代码来源:X500DistinguishedNameTest.cs

示例13: Constructor_String_Empty_Flags

		public void Constructor_String_Empty_Flags ()
		{
			X500DistinguishedName dn = new X500DistinguishedName (String.Empty, X500DistinguishedNameFlags.None);
			Assert.AreEqual (2, dn.RawData.Length, "RawData.Length");
			Assert.AreEqual ("30-00", BitConverter.ToString (dn.RawData), "RawData");
			Empty (dn);
		}
开发者ID:blinds52,项目名称:mono,代码行数:7,代码来源:X500DistinguishedNameTest.cs

示例14: Constructor_String

		public void Constructor_String ()
		{
			X500DistinguishedName dn = new X500DistinguishedName ("OU=Secure Server Certification Authority, O=\"RSA Data Security, Inc.\", C=US");
			Assert.IsNotNull (dn.Oid, "Oid");
			Assert.IsNull (dn.Oid.Value, "Oid.Value");
			Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
			RsaIssuer (dn);
		}
开发者ID:blinds52,项目名称:mono,代码行数:8,代码来源:X500DistinguishedNameTest.cs

示例15: GetIssuers

        //
        // Used only by client SSL code, never returns null.
        //
        private string[] GetIssuers()
        {
            string[] issuers = new string[0];

            if (IsValidContext)
            {
#if MONO_NOT_IMPLEMENTED
                IssuerListInfoEx issuerList = (IssuerListInfoEx)SSPIWrapper.QueryContextAttributes(m_SecModule, m_SecurityContext, ContextAttribute.IssuerListInfoEx);
                try
                {
                    if (issuerList.cIssuers>0) {
                        unsafe {
                            uint count = issuerList.cIssuers;
                            issuers = new string[issuerList.cIssuers];
                            _CERT_CHAIN_ELEMENT* pIL = (_CERT_CHAIN_ELEMENT*)issuerList.aIssuers.DangerousGetHandle();
                            for (uint i =0; i<count; ++i) {
                                _CERT_CHAIN_ELEMENT* pIL2 = pIL + i;
                                uint size = pIL2->cbSize;
                                byte* ptr = (byte*)(pIL2->pCertContext);
                                byte[] x = new byte[size];
                                for (uint j=0; j<size; j++) {
                                    x[j] = *(ptr + j);
                                }
                                // Oid oid = new Oid();
                                // oid.Value = "1.3.6.1.5.5.7.3.2";
                                // Value of issuers[i] can be an empty string when size of x is 0.
                                X500DistinguishedName x500DistinguishedName = new X500DistinguishedName(x);
                                issuers[i] = x500DistinguishedName.Name;
                                GlobalLog.Print("SecureChannel#" + ValidationHelper.HashString(this) + "::GetIssuers() IssuerListEx[" + i + "]:" + issuers[i]);
                            }
                        }
                    }
                }
                finally
                {
                    if (issuerList.aIssuers != null)
                    {
                        issuerList.aIssuers.Close();
                    }
                }
#endif
            }
            return issuers;
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:47,代码来源:_SecureChannel.cs


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