|
| |

VB.NET - Fortgeschrittene| Decrypt docum. with x509Certificate2, preset passw. to suppress passw. dialog | |  | | Autor: LastUser | | Datum: 22.03.13 15:07 |
| Hi,
I want to decrypt an Document with the matching private key under Windows high security conditions. But everytime the CSP asks for the password to grant access.
I need to suppress the password dialog and insert the password programmatically.
Spoiler:
I have installed the X509 software certificate in certificate store under high security conditions. I fetched it as X509Certificates2 from store, encryption works, decryption works but password dialog appears. How can I set the password beforehand, so that it is already known by CSP and the access to private key operations will be granted, without password dialog?
Full story.
I tried following steps:
1. Encryption with x509 software certificate (public key)
The x509 certificate (cert) has been importet from the certificate store
Public Function EncryptWithCertPubKey(cert As _
System.Security.Cryptography.X509Certificates.X509Certificate2, data As _
Byte()) As Byte()
Dim rsa As System.Security.Cryptography.RSACryptoServiceProvider = _
TryCast(cert.PublicKey.Key, _
System.Security.Cryptography.RSACryptoServiceProvider)
Return rsa.Encrypt(data, True)
End Function 2. Decryption with x509 software certificate (private key)
The password (certPass) was set when installing the certificate into the certificate store under high security conditions.
The export to raw data seemed to be a way to do this and simutanously put in the password for suppressing the dialog.
Public Function DecryptWithCertKey(cert As _
System.Security.Cryptography.X509Certificates.X509Certificate2, certPass As _
String, data As Byte()) As Byte()
Dim rawdata As Byte() = cert.Export( _
Security.Cryptography.X509Certificates.X509ContentType.Pkcs12, certPass)
Dim cert2 As New _
System.Security.Cryptography.X509Certificates.X509Certificate2(rawdata, _
certPass)
Dim rsa2 As System.Security.Cryptography.RSACryptoServiceProvider = _
TryCast(cert2.PrivateKey, _
System.Security.Cryptography.RSACryptoServiceProvider)
Return rsa2.Decrypt(data, True)
End Function But again the password dialog appears while accessing the private key, event though the pass is given already.
cert.Export(Security.Cryptography.X509Certificates.X509ContentType.Pkcs12, _
certPass) I found out that there is a Function in CSP-Parameters to preset the Password, so it should be already known for the CSP, and no dialog might appear if it works.
i.e.:
Dim certPass As New System.Security.SecureString
Dim cspp As New System.Security.Cryptography.CspParameters(1, "Microsoft Strong" & _
"Cryptographic Provider")
cspp.KeyPassword = certPass But I don't know how to handle it, because I have'nt found a way to insert CSP-Parameters to X509Certificates2, neither to RSACryptoprovider (while using X509Certificates2).
Any help is appreciated. |  |
 | Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
  |
|
sevISDN 1.0 
Überwachung aller eingehender Anrufe!
Die DLL erkennt alle über die CAPI-Schnittstelle eingehenden Anrufe und teilt Ihnen sogar mit, aus welchem Ortsbereich der Anruf stammt. Weitere Highlights: Online-Rufident, Erkennung der Anrufbehandlung u.v.m. Weitere InfosTipp des Monats Neu! sevPopUp 2.0 
Dynamische Kontextmenüs!
Erstellen Sie mit nur wenigen Zeilen Code Kontextmenüs dynamisch zur Laufzeit. Vordefinierte Styles (XP, Office, OfficeXP, Vista oder Windows 8) erleichtern die Anpassung an die eigenen Anwendung... Weitere Infos
|
| |
|
Copyright ©2000-2025 vb@rchiv Dieter Otter Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.
Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel
|
|