从资源visual basic导入X509Certificates

时间:2015-11-14 19:19:46

标签: vb.net visual-studio visual-studio-2010 visual-studio-2015 x509certificate

 Dim x509Store As New X509Store(StoreName.Root, StoreLocation.CurrentUser)
    Dim cert = My.Resources.Facebook_com
    x509Store.Open(OpenFlags.MaxAllowed)
    x509Store.Add(cert)
    x509Store.Close()

x509Store.Add(cert)行中的问题显示此错误“类型'1维数组字节'的值无法转换为system.cryptography.x509certificats。 x509certificats2"

1 个答案:

答案 0 :(得分:0)

从资源获取的数据是字节数组。

您应该先将其转换为证书对象。

你可以试试这个:

Sub Main()
    Dim x509Store As New X509Store(StoreName.Root, StoreLocation.CurrentUser)
    Dim certificateBytes() As Byte = My.Resources.Facebook_com
    Dim certificateObject As New X509Certificate2(certificateBytes)
    x509Store.Open(OpenFlags.MaxAllowed)
    x509Store.Add(certificateObject)
    x509Store.Close()
End Sub