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


C# Pkcs11UriBuilder.ToString方法代码示例

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


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

示例1: _01_Pkcs11UriInSignatureCreationApplication

        public void _01_Pkcs11UriInSignatureCreationApplication()
        {
            if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 0)
                Assert.Inconclusive("Test cannot be executed on this platform");

            // PKCS#11 URI can be acquired i.e. from configuration file as a simple string...
            string uri = @"<pkcs11:serial=7BFF2737350B262C;
                            type=private;
                            object=John%20Doe
                            ?module-path=pkcs11.dll&
                            pin-value=11111111>";

            Assert.IsNotNull(uri);

            // ...or it can be easily constructed with Pkcs11UriBuilder
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.Serial = "7BFF2737350B262C";
            pkcs11UriBuilder.Type = CKO.CKO_PRIVATE_KEY;
            pkcs11UriBuilder.Object = "John Doe";
            pkcs11UriBuilder.ModulePath = "pkcs11.dll";
            pkcs11UriBuilder.PinValue = "11111111";
            uri = pkcs11UriBuilder.ToString();

            Assert.IsNotNull(uri);

            // Warning: Please note that PIN stored in PKCS#11 URI can pose a security risk and therefore other options
            //          should be carefully considered. For example an application may ask for a PIN with a GUI dialog etc.

            // Use PKCS#11 URI acquired from Settings class to identify private key in signature creation method
            byte[] signature = SignData(ConvertUtils.Utf8StringToBytes("Hello world"), Settings.PrivateKeyUri);

            // Do something interesting with the signature
            Assert.IsNotNull(signature);
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:34,代码来源:_27_Pkcs11UriUtilsTest.cs

示例2: Pkcs11UriInSignatureCreationApplication

        public void Pkcs11UriInSignatureCreationApplication()
        {
            byte[] dataToSign = ConvertUtils.Utf8StringToBytes("Hello world");
            
            // PKCS#11 URI can be acquired i.e. from configuration file as a simple string...
            string uri = @"<pkcs11:serial=7BFF2737350B262C;
                            type=private;
                            object=John%20Doe
                            ?module-path=siecap11.dll&
                            pin-value=11111111>";

            // ...or it can be easily constructed with Pkcs11UriBuilder
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.Serial = "7BFF2737350B262C";
            pkcs11UriBuilder.Type = CKO.CKO_PRIVATE_KEY;
            pkcs11UriBuilder.Object = "John Doe";
            pkcs11UriBuilder.ModulePath = "siecap11.dll";
            pkcs11UriBuilder.PinValue = "11111111";
            uri = pkcs11UriBuilder.ToString();

            // Warning: Please note that PIN stored in PKCS#11 URI can pose a security risk and therefore other options
            //          should be carefully considered. For example an application may ask for a PIN with a GUI dialog etc.

            // Use PKCS#11 URI to identify private key in signature creation method
            byte[] signature = SignData(dataToSign, uri);

            // Do something interesting with the signature
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:28,代码来源:Pkcs11UriAndBuilderExample.cs

示例3: ModelWithoutValue

        public void ModelWithoutValue()
        {
            string uri = @"pkcs11:model=";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.Model = string.Empty;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == true);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.Model == string.Empty);
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:17,代码来源:Pkcs11UriAndBuilderTest.cs

示例4: VendorSpecificQueryAttributeWithoutValue

        public void VendorSpecificQueryAttributeWithoutValue()
        {
            string uri = @"pkcs11:?vendor=";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.UnknownQueryAttributes = new Dictionary<string, List<string>>();
            pkcs11UriBuilder.UnknownQueryAttributes.Add("vendor", new List<string> { string.Empty });
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes != null && pkcs11uri.UnknownQueryAttributes.Count == 1);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes["vendor"].Count == 1);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes["vendor"][0] == string.Empty);
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:20,代码来源:Pkcs11UriAndBuilderTest.cs

示例5: UriWithoutQueryAttributes

        public void UriWithoutQueryAttributes()
        {
            string uri = @"pkcs11:";
            uri += @"library-manufacturer=foo;library-description=bar;library-version=1;";
            uri += @"slot-manufacturer=foo;slot-description=bar;slot-id=1;";
            uri += @"manufacturer=foo;model=bar;serial=foo;token=bar;";
            uri += @"type=private;object=foo;id=%62%61%72";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.LibraryManufacturer = "foo";
            pkcs11UriBuilder.LibraryDescription = "bar";
            pkcs11UriBuilder.LibraryVersion = "1";
            pkcs11UriBuilder.SlotManufacturer = "foo";
            pkcs11UriBuilder.SlotDescription = "bar";
            pkcs11UriBuilder.SlotId = 1;
            pkcs11UriBuilder.Manufacturer = "foo";
            pkcs11UriBuilder.Model = "bar";
            pkcs11UriBuilder.Serial = "foo";
            pkcs11UriBuilder.Token = "bar";
            pkcs11UriBuilder.Type = CKO.CKO_PRIVATE_KEY;
            pkcs11UriBuilder.Object = "foo";
            pkcs11UriBuilder.Id = ConvertUtils.Utf8StringToBytes("bar");
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == true);
            Assert.IsTrue(pkcs11uri.DefinesToken == true);
            Assert.IsTrue(pkcs11uri.DefinesObject == true);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes == null);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes == null);
            Assert.IsTrue(pkcs11uri.LibraryManufacturer == "foo");
            Assert.IsTrue(pkcs11uri.LibraryDescription == "bar");
            Assert.IsTrue(pkcs11uri.LibraryVersion == "1.0");
            Assert.IsTrue(pkcs11uri.SlotManufacturer == "foo");
            Assert.IsTrue(pkcs11uri.SlotDescription == "bar");
            Assert.IsTrue(pkcs11uri.SlotId == 1);
            Assert.IsTrue(pkcs11uri.Manufacturer == "foo");
            Assert.IsTrue(pkcs11uri.Model == "bar");
            Assert.IsTrue(pkcs11uri.Serial == "foo");
            Assert.IsTrue(pkcs11uri.Token == "bar");
            Assert.IsTrue(pkcs11uri.Type == CKO.CKO_PRIVATE_KEY);
            Assert.IsTrue(pkcs11uri.Object == "foo");
            Assert.IsTrue(Helpers.ByteArraysMatch(pkcs11uri.Id, ConvertUtils.Utf8StringToBytes("bar")));
            Assert.IsTrue(pkcs11uri.ModulePath == null);
            Assert.IsTrue(pkcs11uri.ModuleName == null);
            Assert.IsTrue(pkcs11uri.PinValue == null);
            Assert.IsTrue(pkcs11uri.PinSource == null);
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:50,代码来源:Pkcs11UriAndBuilderTest.cs

示例6: ModulePathWithValidValue

        public void ModulePathWithValidValue()
        {
            string uri = @"pkcs11:?module-path=" + _pk11QueryChars + _pctEncodedUnicodeChar;

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.ModulePath = _pk11QueryChars + _unicodeChar;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.ModulePath == _pk11QueryChars + _unicodeChar);
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:17,代码来源:Pkcs11UriAndBuilderTest.cs

示例7: UriWithoutPathAttributes

        public void UriWithoutPathAttributes()
        {
            string uri = @"pkcs11:";
            uri += @"?";
            uri += @"module-path=foo&module-name=bar&";
            uri += @"pin-value=foo&pin-source=bar";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.ModulePath = "foo";
            pkcs11UriBuilder.ModuleName = "bar";
            pkcs11UriBuilder.PinValue = "foo";
            pkcs11UriBuilder.PinSource = "bar";
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes == null);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes == null);
            Assert.IsTrue(pkcs11uri.LibraryManufacturer == null);
            Assert.IsTrue(pkcs11uri.LibraryDescription == null);
            Assert.IsTrue(pkcs11uri.LibraryVersion == null);
            Assert.IsTrue(pkcs11uri.SlotManufacturer == null);
            Assert.IsTrue(pkcs11uri.SlotDescription == null);
            Assert.IsTrue(pkcs11uri.SlotId == null);
            Assert.IsTrue(pkcs11uri.Manufacturer == null);
            Assert.IsTrue(pkcs11uri.Model == null);
            Assert.IsTrue(pkcs11uri.Serial == null);
            Assert.IsTrue(pkcs11uri.Token == null);
            Assert.IsTrue(pkcs11uri.Type == null);
            Assert.IsTrue(pkcs11uri.Object == null);
            Assert.IsTrue(Helpers.ByteArraysMatch(pkcs11uri.Id, null));
            Assert.IsTrue(pkcs11uri.ModulePath == "foo");
            Assert.IsTrue(pkcs11uri.ModuleName == "bar");
            Assert.IsTrue(pkcs11uri.PinValue == "foo");
            Assert.IsTrue(pkcs11uri.PinSource == "bar");
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:40,代码来源:Pkcs11UriAndBuilderTest.cs

示例8: IdWithoutValue

        public void IdWithoutValue()
        {
            string uri = @"pkcs11:id=";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.Id = new byte[0];
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == true);
            Assert.IsTrue(pkcs11uri.Id != null && pkcs11uri.Id.Length == 0);
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:17,代码来源:Pkcs11UriAndBuilderTest.cs

示例9: _081_PinSourceWithValidValue

        public void _081_PinSourceWithValidValue()
        {
            string uri = @"pkcs11:?pin-source=" + _pk11QueryChars + _pctEncodedUnicodeChar;

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.PinSource = _pk11QueryChars + _unicodeChar;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.PinSource == _pk11QueryChars + _unicodeChar);
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:17,代码来源:_01_Pkcs11UriAndBuilderTest.cs

示例10: _079_VendorSpecificPathAttributeWithoutValue

        public void _079_VendorSpecificPathAttributeWithoutValue()
        {
            string uri = @"pkcs11:vendor=";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.UnknownPathAttributes.Add("vendor", string.Empty);
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes.Count == 1);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes["vendor"] == string.Empty);
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:18,代码来源:_01_Pkcs11UriAndBuilderTest.cs

示例11: _077_VendorSpecificPathAttributeWithValidNameAndValue

        public void _077_VendorSpecificPathAttributeWithValidNameAndValue()
        {
            string uri = @"pkcs11:" + _pk11VendorAttrNameChars + "=" + _pk11PathChars + _pctEncodedUnicodeChar;

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.UnknownPathAttributes.Add(_pk11VendorAttrNameChars, _pk11PathChars + _unicodeChar);
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes.Count == 1);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes[_pk11VendorAttrNameChars] == _pk11PathChars + _unicodeChar);
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:18,代码来源:_01_Pkcs11UriAndBuilderTest.cs

示例12: _076_VendorSpecificPathAttributeWithInvalidName

        public void _076_VendorSpecificPathAttributeWithInvalidName()
        {
            string uri = @"pkcs11:.=" + _pk11PathChars + _pctEncodedUnicodeChar;

            try
            {
                // Build URI
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.UnknownPathAttributes.Add(".", _pk11PathChars + _unicodeChar);
                Assert.IsTrue(uri == pkcs11UriBuilder.ToString());
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is Pkcs11UriException);
            }

            try
            {
                // Parse URI
                new Pkcs11Uri(uri);
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is Pkcs11UriException);
            }
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:28,代码来源:_01_Pkcs11UriAndBuilderTest.cs

示例13: _005_UriWithoutAttributes

        public void _005_UriWithoutAttributes()
        {
            string uri = @"pkcs11:";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.UnknownPathAttributes.Count == 0);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes.Count == 0);
            Assert.IsTrue(pkcs11uri.LibraryManufacturer == null);
            Assert.IsTrue(pkcs11uri.LibraryDescription == null);
            Assert.IsTrue(pkcs11uri.LibraryVersion == null);
            Assert.IsTrue(pkcs11uri.SlotManufacturer == null);
            Assert.IsTrue(pkcs11uri.SlotDescription == null);
            Assert.IsTrue(pkcs11uri.SlotId == null);
            Assert.IsTrue(pkcs11uri.Manufacturer == null);
            Assert.IsTrue(pkcs11uri.Model == null);
            Assert.IsTrue(pkcs11uri.Serial == null);
            Assert.IsTrue(pkcs11uri.Token == null);
            Assert.IsTrue(pkcs11uri.Type == null);
            Assert.IsTrue(pkcs11uri.Object == null);
            Assert.IsTrue(Helpers.ByteArraysMatch(pkcs11uri.Id, null));
            Assert.IsTrue(pkcs11uri.ModulePath == null);
            Assert.IsTrue(pkcs11uri.ModuleName == null);
            Assert.IsTrue(pkcs11uri.PinValue == null);
            Assert.IsTrue(pkcs11uri.PinSource == null);
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:33,代码来源:_01_Pkcs11UriAndBuilderTest.cs

示例14: _038_LibraryDescriptionWithoutValue

        public void _038_LibraryDescriptionWithoutValue()
        {
            string uri = @"pkcs11:library-description=";

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.LibraryDescription = string.Empty;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == true);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.LibraryDescription == string.Empty);
        }
开发者ID:Pkcs11Interop,项目名称:Pkcs11Interop,代码行数:17,代码来源:_01_Pkcs11UriAndBuilderTest.cs

示例15: KnownTypes

        public void KnownTypes()
        {
            string[] uris = new string[]
            {
                @"pkcs11:type=public",
                @"pkcs11:type=private",
                @"pkcs11:type=cert",
                @"pkcs11:type=secret-key",
                @"pkcs11:type=data"
            };

            foreach (string uri in uris)
            {
                // Parse URI
                Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
                Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
                Assert.IsTrue(pkcs11uri.DefinesSlot == false);
                Assert.IsTrue(pkcs11uri.DefinesToken == false);
                Assert.IsTrue(pkcs11uri.DefinesObject == true);
                Assert.IsTrue(pkcs11uri.Type != null);

                // Build URI
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.Type = pkcs11uri.Type;
                Assert.IsTrue(uri == pkcs11UriBuilder.ToString());
            }
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:27,代码来源:Pkcs11UriAndBuilderTest.cs


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