gpt4 book ai didi

.net - 如何始终启用要求智能卡引脚的对话框?

转载 作者:行者123 更新时间:2023-12-04 07:09:04 25 4
gpt4 key购买 nike

设想

我正在尝试使用证书来签署文件。
我第一次签名时,操作系统会提示用户设置 PIN 的对话框,但下次不会。
出于安全原因,我每次签名时都需要操作系统向用户询问 PIN。
有谁知道怎么做?

这是代码:

''// create ContentInfo
Dim content As New ContentInfo(bytesContenido)

''// create a signer
Dim signer As New CmsSigner(certificado)

''// SignedCms represents signed data
Dim signedMessage As New SignedCms(content)

''// sign the data
signedMessage.ComputeSignature(signer, False)

''// create and return PKCS #7 byte array
Return signedMessage.Encode()

在某些页面上,我发现使用 CryptSetProvParam可以清洁别针,但到目前为止还不起作用。

该声明:
<DllImport("advapi32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function CryptSetProvParam(ByVal hProv As IntPtr, ByVal dwParam As Int32, ByVal pbData As Byte(), ByVal dwFlags As Int32) As Boolean

End Function

调用:
Public punteroContexto As New System.IntPtr     ''// Obtenido usando CryptAcquireContext
Public Const PP_SIGNATURE_PIN As UInt32 = 33

If (Not CryptSetProvParam(punteroContexto, PP_SIGNATURE_PIN, Nothing, 0)) Then
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error)
End If

错误:

Invalid type specified. (Exception from HRESULT: 0x8009000A)



还使用多线程进行测试(使用另一个线程仅用于签名),但它不起作用。

非常感谢!

最佳答案

[DllImport("Advapi32.dll", SetLastError = true)]
public static extern bool CryptSetProvParam(IntPtr hProv, uint dwParam, IntPtr pvData, uint dwFlags);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool CryptAcquireContext(ref IntPtr hProv,
string pszContainer, string pszProvider, uint dwProvType, uint dwFlags);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern void CryptReleaseContext(IntPtr hProv, uint dwFlags);

static public bool ClearPINCache2(RSACryptoServiceProvider key)
{
const uint PP_KEYEXCHANGE_PIN = 32;
const uint PP_SIGNATURE_PIN = 33;
bool bretval = false;

IntPtr hProv = IntPtr.Zero;

if (CryptAcquireContext(ref hProv, key.CspKeyContainerInfo.KeyContainerName,
key.CspKeyContainerInfo.ProviderName, (uint)key.CspKeyContainerInfo.ProviderType, 0))
{
if ((CryptSetProvParam(hProv, PP_KEYEXCHANGE_PIN, IntPtr.Zero, 0) == true) &&
(CryptSetProvParam(hProv, PP_SIGNATURE_PIN, IntPtr.Zero, 0) == true))
{
bretval = true;
}
}

if (hProv != IntPtr.Zero)
{
CryptReleaseContext(hProv, 0);
hProv = IntPtr.Zero;
}

return bretval;
}

关于.net - 如何始终启用要求智能卡引脚的对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/654957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com