gpt4 book ai didi

.net - 清除 PIN 缓存智能卡

转载 作者:行者123 更新时间:2023-12-01 03:31:31 31 4
gpt4 key购买 nike

在 .net 中,我正在对 ssl 上的网络服务发出网络请求。对于密码学,我必须使用来自受 PIN 码保护的 USB 安全卡设备的证书

我的网络请求代码......

Dim lRequest As HttpWebRequest
lRequest = WebRequest.Create(lAddress)
lRequest.Method = "POST"
lRequest.KeepAlive = True
lRequest.ProtocolVersion = HttpVersion.Version11
lRequest.ContentType = "text/xml; charset=utf-8"
lRequest.ContentLength = lRequestContent.Length
lRequest.Headers.Add("SOAPAction", "")
lRequest.ClientCertificates.Add(gcert)

为了让通话正常进行...

ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)

Public Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
Return True
End Function

其中 gcert 是来自 windows 个人商店的证书 ...

Public gcert As X509Certificate2

Dim store As New X509Store(StoreName.My, StoreLocation.CurrentUser)
store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
...

所有这些工作正常:当我发送我的 webRequest 时,系统提示我输入 PIN,然后我收到来自网络服务的响应。如果我正在调用其他电话,我不会再次收到输入 PIN 的提示,但所有电话都能正常工作。

但现在我的问题是:我想清除 PIN 缓存以便在每次调用时再次提示输入 PIN 或者如果我告诉我的程序这样做(例如“断开连接” "按钮或 1000 万之后的超时)我无法成功重置 PIN 以便在下次通话时再次提示...

经过一番研究,我尝试了这个:

<DllImport("schannel.dll", SetLastError:=True)> _
Private Function SslEmptyCache(ByVal pszTargetName As IntPtr, ByVal dwFlags As UInt32) As Boolean
End Function

Public Function SslEmptyCache() As Boolean
WriteTrace("> SslEmptyCache")

Try

Return SslEmptyCache(IntPtr.Zero, 0)

Catch ex As Exception
WriteTrace("Echec SslEmptyCache")
End Try

Return False

End Function

还有这个

ClearPINCache(gcert.PrivateKey)


Public Function ClearPINCache(ByVal key As RSACryptoServiceProvider) As Boolean

Const PP_KEYEXCHANGE_PIN As UInt32 = 32
Const PP_SIGNATURE_PIN As UInt32 = 33
Dim bretval As Boolean = False

Dim hProv As IntPtr = IntPtr.Zero

If (CryptAcquireContext(hProv, key.CspKeyContainerInfo.KeyContainerName, key.CspKeyContainerInfo.ProviderName, CUInt(key.CspKeyContainerInfo.ProviderType), 0)) Then
If ((CryptSetProvParam(hProv, PP_KEYEXCHANGE_PIN, Nothing, 0) = True) And (CryptSetProvParam(hProv, PP_SIGNATURE_PIN, Nothing, 0) = True)) Then
bretval = True
End If
End If

If (hProv <> IntPtr.Zero) Then
CryptReleaseContext(hProv, 0)
hProv = IntPtr.Zero
End If

Return bretval

End Function

clearPINCahe 函数似乎什么也没做

SslEmptyCache 函数清除了一些内容,但在下一次调用后我没有再次提示输入 PIN,但我收到此错误“请求已中止:无法创建 SSL/TLS 安全通道。”就像我没有在调用中提供 clientCertificate 一样

有人知道我遗漏了什么吗?

谢谢

最佳答案

如果您使用的是网页而不是 Windows 窗体,也许您可​​以通过使用页眉来阻止页面缓存?

有点像

Response.Cache.SetCacheability(HttpCacheability.NoCache)

关于.net - 清除 PIN 缓存智能卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15433493/

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