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


C# X509Name.GetEncoded方法代码示例

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


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

示例1: compositeTest

		private void compositeTest()
		{
			//
			// composite test
			//
			byte[] enc = Hex.Decode("305e310b300906035504061302415531283026060355040a0c1f546865204c6567696f6e206f662074686520426f756e637920436173746c653125301006035504070c094d656c626f75726e653011060355040b0c0a4173636f742056616c65");
			X509Name n = X509Name.GetInstance(Asn1Object.FromByteArray(enc));

			if (!n.ToString().Equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale"))
			{
				Fail("Failed composite to string test got: " + n.ToString());
			}

            IDictionary symbols = X509Name.DefaultSymbols;
			if (!n.ToString(true, symbols).Equals("L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU"))
			{
                Fail("Failed composite to string test got: " + n.ToString(true, symbols));
			}

			n = new X509Name(true, "L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU");
			if (!n.ToString().Equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale"))
			{
				Fail("Failed composite to string reversal test got: " + n.ToString());
			}

			n = new X509Name("C=AU, O=The Legion of the Bouncy Castle, L=Melbourne + OU=Ascot Vale");

			MemoryStream bOut = new MemoryStream();
			Asn1OutputStream aOut = new Asn1OutputStream(bOut);

			aOut.WriteObject(n);

			byte[] enc2 = bOut.ToArray();

			if (!Arrays.AreEqual(enc, enc2))
			{
				Fail("Failed composite string to encoding test");
			}

			//
			// dud name test - handle empty DN without barfing.
			//
			n = new X509Name("C=CH,O=,OU=dummy,[email protected]");

			n = X509Name.GetInstance(Asn1Object.FromByteArray(n.GetEncoded()));
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:46,代码来源:X509NameTest.cs

示例2: PerformTest


//.........这里部分代码省略.........

			if (name1.Equivalent(name2))
			{
				Fail("Failed subset name test");
			}


			compositeTest();


			//
			// getValues test
			//
			ArrayList v1 = name1.GetValues(X509Name.O);

			if (v1.Count != 1 || !v1[0].Equals("The Legion of the Bouncy Castle"))
			{
				Fail("O test failed");
			}

			ArrayList v2 = name1.GetValues(X509Name.L);

			if (v2.Count != 1 || !v2[0].Equals("Melbourne"))
			{
				Fail("L test failed");
			}

			//
			// general subjects test
			//
			for (int i = 0; i != subjects.Length; i++)
			{
				X509Name name = new X509Name(subjects[i]);
				byte[] encodedName = name.GetEncoded();
				name = X509Name.GetInstance(Asn1Object.FromByteArray(encodedName));

				if (!name.ToString().Equals(subjects[i]))
				{
					Fail("Failed regeneration test " + i);
				}
			}

			//
			// sort test
			//
			X509Name unsorted = new X509Name("SERIALNUMBER=BBB + CN=AA");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("CN=AA+SERIALNUMBER=BBB"))
			{
				Fail("Failed sort test 1");
			}

			unsorted = new X509Name("CN=AA + SERIALNUMBER=BBB");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("CN=AA+SERIALNUMBER=BBB"))
			{
				Fail("Failed sort test 2");
			}

			unsorted = new X509Name("SERIALNUMBER=B + CN=AA");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("SERIALNUMBER=B+CN=AA"))
			{
				Fail("Failed sort test 3");
			}
开发者ID:randombit,项目名称:hacrypto,代码行数:66,代码来源:X509NameTest.cs


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