Encrypt File using User Supplied Password

hkinser

New member
Joined
Jan 8, 2007
Messages
1
Programming Experience
1-3
Hello everyone.

I've read several articles on the internet in trying to figure this out; however, those article seem a bit over my head apparently and I can't seem to find a code example that is simple and to the point to implement.

I'm coding a password manager program in vb 2005. All that is left to do is obtain a password from the user the first time they start the program, and use that password as the encryption key in creating the file that will hold the data from the listview control.

For now, the login form is simply taking the password the user enters and encrypting it inside a separate file for now as you will see below - the file itself is not encrypted. I have all the forms complete and the listview data is writing to a currently unencrypted file for now. I just want to make it all one file with the user password being the key to encrypt it all.

Here is the login code I'm using if we can somehow modify it to do what I'm looking for:

If txtUserPsw.Text = txtPswVerify.Text And Me.txtPswVerify.Text.Length >= 8 Then
Try
' Obtain a FileStream object.
Dim aFileStream As New FileStream(AppPath(False) & "\passsafe.bin", FileMode.Create)
' Obtain a BinaryWriter object.
Dim aBinaryWriter As New BinaryWriter(aFileStream)
' Encrypt the new password and binary write to a binary file.
aBinaryWriter.Write(EncryptPassword.EncryptString(Me.txtPswVerify.Text))
' Close the FileStream and the BinaryWriter objects.
aFileStream.Close()
aBinaryWriter.Close()
' Message user.
MessageBox.Show("Password was encrypted and saved. Don't forget it!")
'Display Main form (Frmlogin)
Dim safe As New frmSafe
'Hides login form
Me.Visible = False
safe.ShowDialog()
'disposes login form on exit of main form
'Application.Exit()
Me.Close()
Catch ex As Exception
' Message user.
MessageBox.Show("Password was not saved. ERROR: " & ex.Message)
End Try
End If

Thanks everyone!

Sincerely,
 
Back
Top