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


C# Common.Pkcs11UriBuilder类代码示例

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


Pkcs11UriBuilder类属于Net.Pkcs11Interop.Common命名空间,在下文中一共展示了Pkcs11UriBuilder类的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: _02_LibraryInfoMatches

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

            using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.UseOsLocking))
            {
                LibraryInfo libraryInfo = pkcs11.GetInfo();

                // Empty URI
                Pkcs11Uri pkcs11uri = new Pkcs11Uri(@"pkcs11:");
                Assert.IsTrue(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // Unknown path attribute in URI
                pkcs11uri = new Pkcs11Uri(@"pkcs11:vendor=foobar");
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // All attributes matching
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsTrue(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // LibraryManufacturer nonmatching
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = "foobar";
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // LibraryDescription nonmatching
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = "foobar";
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // LibraryVersion nonmatching
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = "0";
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));
            }
        }
开发者ID:Gianluigi,项目名称:Pkcs11Interop,代码行数:50,代码来源:_27b_Pkcs11UriUtilsTest.cs

示例4: LibraryInfoMatchesHLA

        public void LibraryInfoMatchesHLA()
        {
            using (HLA.Pkcs11 pkcs11 = new HLA.Pkcs11(Settings.Pkcs11LibraryPath, false))
            {
                HLA.LibraryInfo libraryInfo = pkcs11.GetInfo();

                // Empty URI
                Pkcs11Uri pkcs11uri = new Pkcs11Uri(@"pkcs11:");
                Assert.IsTrue(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // Unknown path attribute in URI
                pkcs11uri = new Pkcs11Uri(@"pkcs11:vendor=foobar");
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // All attributes matching
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsTrue(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // LibraryManufacturer nonmatching
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = "foobar";
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // LibraryDescription nonmatching
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = "foobar";
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));

                // LibraryVersion nonmatching
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = "0";
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                Assert.IsFalse(Pkcs11UriUtils.Matches(pkcs11uri, libraryInfo));
            }
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:47,代码来源:Pkcs11UriUtilsTest.cs

示例5: 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

示例6: VendorSpecificQueryAttributeWithValidNameAndValue

        public void VendorSpecificQueryAttributeWithValidNameAndValue()
        {
            string uri = @"pkcs11:?" + _pk11VendorAttrNameChars + "=" + _pk11QueryChars + _pctEncodedUnicodeChar;

            // Build URI
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.UnknownQueryAttributes = new Dictionary<string, List<string>>();
            pkcs11UriBuilder.UnknownQueryAttributes.Add(_pk11VendorAttrNameChars, new List<string> { _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.UnknownQueryAttributes != null && pkcs11uri.UnknownQueryAttributes.Count == 1);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes[_pk11VendorAttrNameChars].Count == 1);
            Assert.IsTrue(pkcs11uri.UnknownQueryAttributes[_pk11VendorAttrNameChars][0] == _pk11QueryChars + _unicodeChar);
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:20,代码来源:Pkcs11UriAndBuilderTest.cs

示例7: LibraryVersionWithTwoDots

        public void LibraryVersionWithTwoDots()
        {
            string uri = @"pkcs11:library-version=1.2.3";

            try
            {
                // Build URI
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryVersion = "1.2.3";
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is Pkcs11UriException);
            }

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

示例8: _06_GetMatchingSlotList

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

            using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.UseOsLocking))
            {
                // Get all slots
                List<Slot> allSlots = pkcs11.GetSlotList(true);
                Assert.IsTrue(allSlots != null && allSlots.Count > 0);

                // Empty URI
                Pkcs11Uri pkcs11uri = new Pkcs11Uri(@"pkcs11:");
                List<Slot> matchedSlots = Pkcs11UriUtils.GetMatchingSlotList(pkcs11uri, pkcs11, true);
                Assert.IsTrue(matchedSlots.Count == allSlots.Count);

                // Unknown path attribute in URI
                pkcs11uri = new Pkcs11Uri(@"pkcs11:vendor=foobar");
                matchedSlots = Pkcs11UriUtils.GetMatchingSlotList(pkcs11uri, pkcs11, true);
                Assert.IsTrue(matchedSlots.Count == 0);

                // All attributes matching one slot
                LibraryInfo libraryInfo = pkcs11.GetInfo();
                SlotInfo slotInfo = allSlots[0].GetSlotInfo();
                TokenInfo tokenInfo = allSlots[0].GetTokenInfo();

                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = libraryInfo.ManufacturerId;
                pkcs11UriBuilder.LibraryDescription = libraryInfo.LibraryDescription;
                pkcs11UriBuilder.LibraryVersion = libraryInfo.LibraryVersion;
                pkcs11UriBuilder.SlotManufacturer = slotInfo.ManufacturerId;
                pkcs11UriBuilder.SlotDescription = slotInfo.SlotDescription;
                pkcs11UriBuilder.SlotId = slotInfo.SlotId;
                pkcs11UriBuilder.Token = tokenInfo.Label;
                pkcs11UriBuilder.Manufacturer = tokenInfo.ManufacturerId;
                pkcs11UriBuilder.Serial = tokenInfo.SerialNumber;
                pkcs11UriBuilder.Model = tokenInfo.Model;
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();

                matchedSlots = Pkcs11UriUtils.GetMatchingSlotList(pkcs11uri, pkcs11, true);
                Assert.IsTrue(matchedSlots.Count == 1);

                // One attribute nonmatching
                pkcs11UriBuilder.Serial = "foobar";
                pkcs11uri = pkcs11UriBuilder.ToPkcs11Uri();
                matchedSlots = Pkcs11UriUtils.GetMatchingSlotList(pkcs11uri, pkcs11, true);
                Assert.IsTrue(matchedSlots.Count == 0);
            }
        }
开发者ID:Gianluigi,项目名称:Pkcs11Interop,代码行数:49,代码来源:_27b_Pkcs11UriUtilsTest.cs

示例9: SlotIdWithValidValue

        public void SlotIdWithValidValue()
        {
            string uri = @"pkcs11:slot-id=18446744073709551615";

            // Build URI without length checking
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder(false);
            pkcs11UriBuilder.SlotId = 18446744073709551615;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI without length checking
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri, false);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == true);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.SlotId == 18446744073709551615);

            // Build URI with length checking
            pkcs11UriBuilder = new Pkcs11UriBuilder(true);
            pkcs11UriBuilder.SlotId = 18446744073709551615;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

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

示例10: VendorSpecificPathAttributeWithIncompleteName

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

            try
            {
                // Build URI
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.UnknownPathAttributes = new Dictionary<string, string>();
                pkcs11UriBuilder.UnknownPathAttributes.Add(string.Empty, _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
                Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is Pkcs11UriException);
            }
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:29,代码来源:Pkcs11UriAndBuilderTest.cs

示例11: LibraryManufacturerWithValidValue

        public void LibraryManufacturerWithValidValue()
        {
            string uri = @"pkcs11:library-manufacturer=" + _pk11PathChars + _pctEncodedUnicodeChar;

            // Build URI without length checking
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder(false);
            pkcs11UriBuilder.LibraryManufacturer = _pk11PathChars + _unicodeChar;
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI without length checking
            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri, false);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == true);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == false);
            Assert.IsTrue(pkcs11uri.LibraryManufacturer == _pk11PathChars + _unicodeChar);

            try
            {
                // Build URI with length checking
                pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.LibraryManufacturer = _pk11PathChars + _unicodeChar;
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is ArgumentOutOfRangeException);
            }

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

示例12: IdWithValidValue

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

            // Note: Builder cannot be used to produce URI like this one

            // 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(Helpers.ByteArraysMatch(pkcs11uri.Id, ConvertUtils.Utf8StringToBytes(_pk11PathChars + _unicodeChar)));

            uri = @"pkcs11:id=%41%42%43%44%45%46%47%48%49%4A%4B%4C%4D%4E%4F%50%51%52%53%54%55%56%57%58%59%5A%61%62%63%64%65%66%67%68%69%6A%6B%6C%6D%6E%6F%70%71%72%73%74%75%76%77%78%79%7A%30%31%32%33%34%35%36%37%38%39%2D%2E%5F%7E%3A%5B%5D%40%21%24%27%28%29%2A%2B%2C%3D%26%C3%A4";

            // Build URI without length checking
            Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder(false);
            pkcs11UriBuilder.Id = ConvertUtils.Utf8StringToBytes(_pk11PathChars + _unicodeChar);
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI without length checking
            pkcs11uri = new Pkcs11Uri(uri, false);
            Assert.IsTrue(pkcs11uri.DefinesLibrary == false);
            Assert.IsTrue(pkcs11uri.DefinesSlot == false);
            Assert.IsTrue(pkcs11uri.DefinesToken == false);
            Assert.IsTrue(pkcs11uri.DefinesObject == true);
            Assert.IsTrue(Helpers.ByteArraysMatch(pkcs11uri.Id, ConvertUtils.Utf8StringToBytes(_pk11PathChars + _unicodeChar)));

            // Build URI with length checking
            pkcs11UriBuilder = new Pkcs11UriBuilder();
            pkcs11UriBuilder.Id = ConvertUtils.Utf8StringToBytes(_pk11PathChars + _unicodeChar);
            Assert.IsTrue(uri == pkcs11UriBuilder.ToString());

            // Parse URI with length checking
            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(Helpers.ByteArraysMatch(pkcs11uri.Id, ConvertUtils.Utf8StringToBytes(_pk11PathChars + _unicodeChar)));
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:42,代码来源:Pkcs11UriAndBuilderTest.cs

示例13: 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

示例14: UnknownType

        public void UnknownType()
        {
            string uri = @"pkcs11:type=otp";

            try
            {
                // Build URI
                Pkcs11UriBuilder pkcs11UriBuilder = new Pkcs11UriBuilder();
                pkcs11UriBuilder.Type = CKO.CKO_OTP_KEY;
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is Pkcs11UriException);
            }

            try
            {
                // Parse URI
                Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);
                Assert.Fail("Exception expected but not thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is Pkcs11UriException);
            }
        }
开发者ID:jariq,项目名称:Pkcs11Interop.URI,代码行数:27,代码来源: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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。