2
In my desktop I have some certificates and I need to select one of them, I would like to know via VN.Net or C# code how to appear a list and I choose the digital certificate I need, without having to assign this list of certificates in a combobox
.
Code
Dim ListaCertificados As New List(Of X509Certificate2)()
Private Sub ReloadCerts()
Dim Store As X509Store = New X509Store(StoreName.My, StoreLocation.CurrentUser)
Store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
Dim _certs As X509Certificate2Collection = Store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, True).Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.DigitalSignature, True)
For Each Certificado In _certs
If Certificado.HasPrivateKey Then
ListaCertificados.Add(Certificado)
Certificado.GetNameInfo(X509NameType.SimpleName, False)
End If
Next
End Sub
Does this help you? http://stackoverflow.com/q/1205295/221800
– Maniero
In a way, yes, but I didn’t understand
X509Certificate2UI
, he presents me with a mistake of not being declared, but has already been declared.– Felipe S
He’s probably not visible in that scope. I wouldn’t know without details.
– Maniero
Here is an example: https://msdn.microsoft.com/pt-br/library/system.security.cryptography.x509certificates.x509certificate2ui(v=vs.90). aspx? Cs-save-lang=1&Cs-lang=Vb#code-snippet-2 ...
– Felipe S
You put
using System.Security.Cryptography.X509Certificates;
?– Maniero
Both this
using System.Security.Cryptography.X509Certificates;
how much thisusing System.Security.Cryptography;
And nothing wrong.'X509Certificate2UI' não está declarado. Ele pode ser inacessível devido ao seu nível de proteção.
– Felipe S
I managed to solve the problem, I had to add the reference System.Security.dll
– Felipe S
Of course, I forgot this, I thought it was already referenced. And it solved everything? If I put as answer, answers your question?
– Maniero
So, this was an unforeseen. The answer to my question is the following code, in which case I got what I wanted.
Dim Store As X509Store = New X509Store(StoreName.My,
StoreLocation.CurrentUser)
Store.Open(OpenFlags.ReadOnly Or
OpenFlags.OpenExistingOnly)
Dim certificateCollection As X509CertificateCollection =
X509Certificate2UI.SelectFromCollection(Store.Certificates,
"Caption", "Message", X509SelectionFlag.SingleSelection)
– Felipe S
Post the answer you then.
– Maniero
I will not post, because the merit was yours in showing the link in the first comment, than in the case, helped me with what I was looking for. I thank!
– Felipe S