作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
设想
我正在尝试使用证书来签署文件。
我第一次签名时,操作系统会提示用户设置 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/
我是一名优秀的程序员,十分优秀!