我有以下通过 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();
}
}
}
}
}
我得到的错误堆栈跟踪是
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:C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\ 中 PkcsTestWindowsApp.Form1.button1_Click(Object sender, EventArgs e) 的第 15 行src\PkcsTestWindowsApp\Form1.cs:第 27 行 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ButtonBase.WndProc(Message& m) 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)在 System.Windows.Forms.Button.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow。WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application .ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms。 Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() in C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop- master\src\PkcsTestWindowsApp\Program.cs:第 19 行m) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager 的 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)。 System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.ThreadContext .RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\src \PkcsTestWindowsApp\Program.cs:第 19 行m) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager 的 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)。 System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.ThreadContext .RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\src \PkcsTestWindowsApp\Program.cs:第 19 行NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager .FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)在 System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\src\PkcsTestWindowsApp\Program.cs:line 19NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager .FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)在 System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\src\PkcsTestWindowsApp\Program.cs:line 19IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.Run(Form mainForm ) 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\src\PkcsTestWindowsApp\Program.cs:line 19 中的 PkcsTestWindowsApp.Program.Main()IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application.Run(Form mainForm ) 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master\src\PkcsTestWindowsApp\Program.cs:line 19 中的 PkcsTestWindowsApp.Program.Main()ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application .ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master \src\PkcsTestWindowsApp\Program.cs:第 19 行ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 在 System.Windows.Forms.Application .ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\Pkcs11Interop-master \src\PkcsTestWindowsApp\Program.cs:第 19 行Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\ Pkcs11Interop-master\src\PkcsTestWindowsApp\Program.cs:第 19 行Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PkcsTestWindowsApp.Program.Main() 在 C:\Users\kashahid\Downloads\Pkcs11Interop-master\ Pkcs11Interop-master\src\PkcsTestWindowsApp\Program.cs:第 19 行