We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,555 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Best way to store short important data

Hello,
I am writing a program and I need to store important data like password, etc. What is the best way to store the password and where is the best way to store it?

2
Contributors
1
Reply
25 Minutes
Discussion Span
2 Years Ago
Last Updated
2
Views
imolorhe
Junior Poster in Training
55 posts since Nov 2009
Reputation Points: 4
Solved Threads: 2
Skill Endorsements: 0

Don't know what your looking for but heres an easy way to encrypt if you only need to keep on the local computer and your not using a database.

This uses the ProtectedData class. You will have to add a Reference to System.Security. When Encrypting and Decrypting with this class only the computer knows the key. It can only be Decrypted on the computer that encyrpted it. It has an option Entrophy which is an extra byte array to add some salt. You would have to read about that. The length of the Entropy has to be in a certain length.

This encrypts to a file and stores it in the app directory.

Imports System.Security.Cryptography

Public Class Form1

Private Sub ButtonEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEncrypt.Click

    Dim Password As String = "BeaverLeaveItToHim"
    Dim MemoryStream As New IO.MemoryStream
    Dim BinaryWriter As New IO.BinaryWriter(MemoryStream)
    Dim EncryptedPassword As Byte()

    'Write anything here you want encrypted in the file.
    BinaryWriter.Write(Password)
    BinaryWriter.Flush()

    EncryptedPassword = ProtectedData.Protect(MemoryStream.ToArray, Nothing, DataProtectionScope.LocalMachine)

    My.Computer.FileSystem.WriteAllBytes(My.Application.Info.DirectoryPath & "\Password.psd", EncryptedPassword, False)

    BinaryWriter.Close()
    MemoryStream.Dispose()

End Sub

Private Sub ButtonDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDecrypt.Click

    Dim EncryptedPassword As Byte() = My.Computer.FileSystem.ReadAllBytes(My.Application.Info.DirectoryPath & "\Password.psd")
    Dim MemoryStream As New IO.MemoryStream(ProtectedData.Unprotect(EncryptedPassword, Nothing, DataProtectionScope.LocalMachine))
    Dim BinaryReader As New IO.BinaryReader(MemoryStream)
    Dim Password As String = BinaryReader.ReadString

    MemoryStream.Dispose()
    BinaryReader.Close()

End Sub

End Class

I should point out that this would only be used to store on a client computer. You would not use this to store permanent information on a server or anything like that. Once the operating system is reinstalled the information will no longer be able to be decrypted. If you need permanent storage then you can see this link on the Msdn website about the RijndaelManaged Class. I think I also saw a code snippet on this site about encryption in the past week or so.

http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(VS.71).aspx

I use both classes. For different reasons.

Unhnd_Exception
Deleted Member

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0600 seconds using 2.66MB