是否可以使用 VB 导入 pfx 文件
Is it possible to import a pfx file with VB
是否可以使用 VB.NET 导入 pfx?我可以使用命令行,但这绝对不是可取的。
编辑:使用此代码,我没有在 mmc 管理单元下看到我的证书。我在调试期间没有遇到异常或任何错误。
Imports System.Security.Cryptography.X509Certificates
Module Module1
Sub Main()
Try
My.Computer.FileSystem.WriteAllBytes(Environment.CurrentDirectory & "\client.pfx", My.Resources.client, False)
Dim sqlCert As New X509Certificate2(Environment.CurrentDirectory & "\client.pfx", "passwordhere")
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
store.Open(OpenFlags.ReadWrite)
store.Add(sqlCert)
store.Close()
Catch ex As Exception
End Try
End Sub
End Module
我正在使用 requireAdministrator
。
已解决:将 StoreLocation.LocalMachine
更改为 StoreLocation.CurrentUser
解决了我的问题。
当然可以。这就是 X509Store
class 的用途。
Dim yourCert As New X509Certificate2("C:\YourPath\cert.pfx", "YourPfxPasswordIfAny")
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
store.Open(OpenFlags.ReadWrite)
store.Add(yourCert)
store.Close()
在此示例中,您需要 运行 您的程序作为提升的管理员,因为我们要导入到 LocalMachine 商店。
所有 classes 都在 System.Security.Cryptography.X509Certificates
命名空间中。
是否可以使用 VB.NET 导入 pfx?我可以使用命令行,但这绝对不是可取的。
编辑:使用此代码,我没有在 mmc 管理单元下看到我的证书。我在调试期间没有遇到异常或任何错误。
Imports System.Security.Cryptography.X509Certificates
Module Module1
Sub Main()
Try
My.Computer.FileSystem.WriteAllBytes(Environment.CurrentDirectory & "\client.pfx", My.Resources.client, False)
Dim sqlCert As New X509Certificate2(Environment.CurrentDirectory & "\client.pfx", "passwordhere")
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
store.Open(OpenFlags.ReadWrite)
store.Add(sqlCert)
store.Close()
Catch ex As Exception
End Try
End Sub
End Module
我正在使用 requireAdministrator
。
已解决:将 StoreLocation.LocalMachine
更改为 StoreLocation.CurrentUser
解决了我的问题。
当然可以。这就是 X509Store
class 的用途。
Dim yourCert As New X509Certificate2("C:\YourPath\cert.pfx", "YourPfxPasswordIfAny")
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
store.Open(OpenFlags.ReadWrite)
store.Add(yourCert)
store.Close()
在此示例中,您需要 运行 您的程序作为提升的管理员,因为我们要导入到 LocalMachine 商店。
所有 classes 都在 System.Security.Cryptography.X509Certificates
命名空间中。