Click here to Skip to main content
15,909,498 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need to store some passwords on a client machine which will be used by a (VB / C#) .net application to connect to a database.
The database-name/password combination is delivered to the client based on a web-service that has domain authentication.
So only allowed database-name/password combinations for that user may be stored on the client machine. The storing is important as the user will not always have access to the webservice.

So after webservice access, a list of database-name/password combinations is saved on the client and can be used afterwords by the client-program.

Though, it is not allowed that the user on the client system can read/redistribute the passwords.

So I am looking for a way to encrypt the passwords on the client in such a way that only my application can decrypt it and use them.

No direct reading or decryption by any other application is allowed.
In my knowledge it is hard to hide an encryption key in a .net application without the possibility to read it by examining the application in an editor or by reading the encrypted settings file through another .net application.

Any ideas in how to achieve this goal?

Thanks!
Posted

Check Microsoft websites for CNG (Cryptography Next Generation) A good place to start is also here[^]
 
Share this answer
 
My first suggestion is that you one way hash the passwords so that they can never be decrypted. Then when a user types in a password you hash it the exact same way and compare it to the stored hash. Here is a function I use to hash passwords.

VB
Public Function HashString(ByVal instrString As String) As String
    'This function will:
    '- Create a SHA2 hash of the incomming parm and return it.
    '  (Hash will be 64 characters long)
  
    'Create an encoding object to ensure the encoding standard for the source text
    Dim Ue As New System.Text.UnicodeEncoding()

    'Retrieve a byte array based on the password
    Dim ByteSourceText() As Byte = Ue.GetBytes(Trim(instrString))

    'Instantiate an SHA2 Provider object
    Dim SHA2 As New System.Security.Cryptography.SHA384Managed

    'Compute the hash value from the source
    Dim ByteHash() As Byte = SHA2.ComputeHash(ByteSourceText)

    'And convert it to String format for return
    Dim strSha2 As String = Convert.ToBase64String(ByteHash)

    Return Convert.ToBase64String(ByteHash)

End Function


You can find a lot more information in the CP Articles.[^] You may want to research salting a hash. And this article[^] seemed to really define the different types of cryptography.

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900