Softhsm2与pkcs11interop错误。对于UInt32,值太大或太小

问题描述 投票:0回答:1

我有通过pkcs11interop库进行softhsm2测试的以下代码

using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI;
using Net.Pkcs11Interop.HighLevelAPI80;
using System;
using System.Collections.Generic;
namespace ExportTest
{
    public class Softhsmtest
    {
        public static Pkcs11InteropFactories Factories = new Pkcs11InteropFactories();
        public static void Test()
        {

            using (Pkcs11 pkcs11 = new Pkcs11(Factories, @"C:\SoftHSM2\lib\softhsm2.dll",AppType.MultiThreaded))
            {
                ISlot slot = pkcs11.GetSlotList(SlotsType.WithTokenPresent)[0];
                using (ISession session = slot.OpenSession(SessionType.ReadWrite))
                {
                    session.Login(CKU.CKU_USER, "1111");                    
                    session.Logout();
                }
            }
        }
    }
}

错误Stacktrace我得到的是

   at System.Convert.ToUInt32(UInt64 value)
   at Net.Pkcs11Interop.Common.ConvertUtils.UInt64ToCKR(UInt64 value)
   at Net.Pkcs11Interop.LowLevelAPI80.Delegates.InitializeWithGetFunctionList(IntPtr libraryHandle)
   at Net.Pkcs11Interop.LowLevelAPI80.Delegates..ctor(IntPtr libraryHandle, Boolean useGetFunctionList)
   at Net.Pkcs11Interop.LowLevelAPI80.Pkcs11..ctor(String libraryPath)
   at Net.Pkcs11Interop.HighLevelAPI80.Pkcs11..ctor(Pkcs11InteropFactories factories, String libraryPath, AppType appType)
   at ExportTest.Softhsmtest.Test() in C:\Users\kashahid\Downloads

\ Pkcs11Interop-master \ Pkcs11Interop-master \ src \ PkcsTestWindowsApp \ Class1.cs:第15行,位于C:\ Users \ kashahid \ Downloads \ Pkcs11Interop-master \ Pkcs11Interop-master \中的PkcsTestWindowsApp.Form1.button1_Click(Object sender,EventArgs e) src \ PkcsTestWindowsApp \ Form1.cs:System.Windows.Forms.OnClick上的System.Windows.Forms.Control.OnClick(EventArgs e)中的第27行(SystemArgs e)System.Windows.Forms.Button.OnMouseUp(MouseArgs e)(MouseAventArgs)在System.Windows.Fornd.BandtonBase.WndProc(Message&m)的System.Windows.Forms.Control.WndProc(Message&m)处的System.Windows.Forms.Control.WmMouseUp(Message&m,MouseButtons按钮,Int32单击)处的mevent)在System.Windows上的System.Windows.Forms.Control.ControlNindWindow.OnMessage(Message&m)处的System.Windows.Forms.Button.WndProc(Message&m)处于System.Windows的System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m) System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW上的.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因)的System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)中的MSG和msg) ,System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)位于C:\ Users中PkcsTestWindowsApp.Program.Main()的System.Windows.Forms.Application.Run(Form mainForm)上的,ApplicationContext context) \ kashahid \ Downloads \ Pkcs11Interop-master \ Pkcs11Interop-master \ src \ PkcsTestWindowsApp \ Program.cs:第19行

https://github.com/Pkcs11Interop/Pkcs11Interop

c# .net-4.5 pkcs#11 pkcs11interop softhsm
1个回答
2
投票

我看到两个问题:

  1. 您正在使用包含多个API中断更改的Pkcs11Interop(主分支)的当前开发版本,并且在它变为稳定版本之前将更改LOT。
  2. 您直接引用Net.Pkcs11Interop.HighLevelAPI80命名空间中的类型,这些类型应该仅在Unix系统上使用。

解决方案:

您应该使用当前的稳定版本 - Pkcs11Interop 4.1.0 - 使用以下代码:

using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI;

namespace ExportTest
{
    public class Softhsmtest
    {
        public static void Test()
        {
            using (Pkcs11 pkcs11 = new Pkcs11(@"C:\SoftHSM2\lib\softhsm2.dll", AppType.MultiThreaded))
            {
                Slot slot = pkcs11.GetSlotList(SlotsType.WithTokenPresent)[0];
                using (Session session = slot.OpenSession(SessionType.ReadWrite))
                {
                    session.Login(CKU.CKU_USER, "1111");
                    session.Logout();
                }
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.