问题标签 [pkcs11interop]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
266 浏览

c# - 如何将 ObjectHandle 从 Pkcs11Interop 转换为 X509 证书或 Pem 格式?

如何将公钥从 Pkcs11Interop 转换为 X509 证书或 pem 格式

0 投票
2 回答
250 浏览

c# - 我正在尝试创建 GOSTR3410 公钥。CKR_ATTRIBUTE_TYPE_INVALID 异常

再会!ObjectHandle我正在尝试基于来自客户端通过发布请求的十六进制字符串创建公钥。

我正在根据文档进行操作,但它返回给我CKR_ATTRIBUTE_TYPE_INVALID例外。

完整的例外消息:Net.Pkcs11Interop.Common.Pkcs11Exception: 'Method C_CreateObject returned CKR_ATTRIBUTE_VALUE_INVALID'

内部异常为空

你能帮我弄清楚我做错了什么吗?

这是我的代码:

0 投票
0 回答
507 浏览

.net - 使用 pkcs11interop 导出/导入密钥

我正在尝试导出/导入私钥和公钥。根据 pkcs11Admin,目前不支持这些操作。

知道怎么做吗?导出前生成密钥的相关属性(CKA_SENSITIVE、CKA_EXTRACTABLE)?我应该在导出之前包装私钥吗?

0 投票
1 回答
1136 浏览

c# - Safenet 5100 的 PKCS 库

我得到了Net.Pkcs11Interop.Common.Pkcs11Exception: 'Method C_EncryptInit returned CKR_KEY_TYPE_INCONSISTENT'错误byte[] result = session.Encrypt(mechanism, objectHandle, inputData);

我正在使用 safenet 5100 etoken 你能帮忙吗?

0 投票
3 回答
2863 浏览

c# - 使用 PKCS#11 导入私钥

我们正在尝试使用 C# 和 PKCS#11 将 RSA 密钥对导入我们的 HSM。使用以下方法导入私钥:

失败并显示错误代码CKR_TEMPLATE_INCONSISTENT。不幸的是,它没有说明不一致的地方。我尝试了各种其他属性组合,但总是失败:-(

如何通过 PKCS#11 正确导入私钥?


注意:使用非常相似的代码导入公钥的工作原理:

0 投票
1 回答
2632 浏览

pkcs#11 - PKCS#11 将私钥解包到 HSM

我了解到我不能简单地通过 PKCS#11 将私钥传输到我的 HSM,我需要先将其打包,然后在 HSM 上解包。所以我暂时在我们的 HSM 上创建了一个 DES3 密钥,然后我想用它来包装(加密)我的 RSA 私钥,然后我想在 HSM 上解开它。

我的代码如下所示:

这不起作用,它失败了CKR_INVALID_MECHANISM

我很确定问题是encryptedPrivateKeyParamsD,我应该以某种方式加密整个密钥。但是怎么做?什么是正确的格式?我在文档中找不到任何关于它的内容:-(

任何想法如何解决这一问题?我只是想使用 PKCS#11 以编程方式将现有的 RSA 私钥放到我们的 HSM 上。

0 投票
0 回答
19 浏览

pkcs11interop - 多平台发行版上的类型定义和各种类型的大小

我对 PKCS11Interop 库在不同操作系统平台上使用类型感到有些困惑。我的理解是,Windows x64 上 long 的大小为 4 个字节,但在 Linux/iOS 64 位上,长度为 8 个字节。这确实反映在公共静态 NativeULongSize 的 Platform.cs 实现中。但是查看 LowLevelAPIXX 源代码,例如 LowLevelAPI80 对应于 Linux (x64),LowLevelAPI81 对应于 Windows (x64),结构定义中使用的 NativeULong 的定义是 UInt64 - 因此将是 8 个字节。这是一个错误 - 至少它似乎是不一致的?

0 投票
0 回答
205 浏览

cryptography - ECDSA 密钥的包装机制

我正在使用 pkcs11interop 生成密钥,并进行包装/解包。这就是我在工作中使用的 https://github.com/Pkcs11Interop/Pkcs11Interop/blob/master/src/Pkcs11Interop/Pkcs11InteropTests/HighLevelAPI/_24_WrapAndUnwrapKeyTest.cs

我可以生成 ECDSA p-256。但问题是我想打包/解包 ECDSA 密钥,我不知道应该使用哪个机制值(CKM_???)。上面的示例使用 CKM_RSA_PKCS,它仅适用于 RSA。IMechanism 机制 = Settings.Factories.MechanismFactory.CreateMechanism(CKM.CKM_RSA_PKCS);

我还尝试在http://wiki.ncryptoki.com/GetFile.aspx?File=%2fdocs%2fpkcs-11v2-20.pdf使用几个 CKM 进行 wrap/upwrap, 但它仍然失败。

如果您对此有任何信息,请帮助与我分享。非常感谢!

0 投票
1 回答
64 浏览

smartcard - PKCS#11 - 在已配置的智能卡上写入新证书时,如何保护智能卡所有者免受恶意智能卡提供商的侵害

我目前正在学习 PKCS#11,有一个我不知道如何处理的场景。

这是场景:

  • 想要从提供商处获取证书的客户输入他的数据,
  • 客户来到供应商设施,在那里他可以获得订购的智能卡,上面写有证书(例如合格的和商业的),
  • 智能卡必须发生两件事:提供商必须为两个证书生成密钥对,然后在卡上写入证书(需要用户 PIN)

据我所知,智能卡有两种类型的用户:普通用户(用户 PIN)和 SO(SO PIN)。

那么问题是什么?当提供商使用用户 PIN 生成密钥和编写证书时,我们可以通过 SetPin 互操作操作以编程方式更改它,或者让客户稍后在家中使用适当的软件更改它。当客户想要为他的智能卡获取新证书时,就会出现问题,而在这个阶段,提供商不知道卡的用户 PIN(即他无法使用卡上的任何加密机制)。如果客户为提供者提供密码,他将能够让客户用他的证书签署一些随机文件,而不是出于正当理由使用 PIN(利用 PKCS#11 机制编写新证书)

所以我的问题是:

有什么方法可以在卡上为某些令牌设置第二个用户 PIN(提供商和客户分开)?我们能否让某些 PKCS#11 机制仅对特定用户可用(例如,仅为提供者生成密钥对,以及仅为客户端使用证书签署文档)?

处理此类问题的标准化方案是什么?我很高兴听到你的意见。

0 投票
1 回答
243 浏览

c# - Softhsm2 出现 pkcs11interop 错误。对于 UInt32,值太大或太小

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

我得到的错误堆栈跟踪是

\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 行

https://github.com/Pkcs11Interop/Pkcs11Interop