Decrypt  
Author Message
Whoisit





PostPosted: .NET Base Class Library, Decrypt Top

Here is what I have to encrypt the info from 4 textboxes and it works OK.
--------------------------------------
Private Sub tlstSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlstSave.Click
If FileCreated = True Then
StrContents = ""
StrContents = Me.TxtName.Text & vbCr
StrContents = StrContents & Me.LblPW.Text & vbCr
StrContents = StrContents & Me.LblD.Text & vbCr
StrContents = StrContents & Me.LblT.Text & vbCr

'Send the password to the CreateKey function.
bytKey = CreateKey(PassCreate.txtPassCreate.Text)
'Send the password to the CreateIV function.
bytIV = CreateIV(PassCreate.txtPassCreate.Text)
Try

' Encrypt the string to an array of bytes.
Dim encrypted As Byte() = encryptStringToBytes_AES(StrContents, bytKey, bytIV)

'create a StreamWriter Object by opening file for append
swPass = IO.File.AppendText("My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData." + FileName + "File.txt")

'write name on a seperate line in the file
swPass.WriteLine(System.Text.Encoding.UTF8.GetString(encrypted))

'close the file
swPass.Close()

Catch ex As Exception
'handles any errors
MessageBox.Show(ex.Message, "PGS", _
MessageBoxButtons.OK, MessageBoxIcon.Information)

End Try
End If
Me.TxtName.Text = ""
Me.LblPW.Text = ""
Me.LblD.Text = ""
Me.LblT.Text = ""
End Sub
---------------------------------------------

This is what I use to open the file, what I can't figure is how I decrypt it. The Encrypt and Decrypt routines are what I downloaded from a website.
---------------------------------------------
Public Sub SelectedFile()
If My.Computer.FileSystem.FileExists("My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData." + FileName + "File.txt") Then

Dim decrypted As Byte() = decryptStringFromBytes_AES(StrContents, bytKey, bytIV)

StrContents = My.Computer.FileSystem.ReadAllText("My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData." + FileName + "File.txt")
Dim lines() As String = StrContents.Split(vbCr)
If lines.Length >= LineGroupCount + 4 Then
Me.TxtName.Text = Trim(Replace(lines(LineGroupCount), vbCr, ""))
Me.LblPW.Text = Trim(Replace(lines(LineGroupCount + 1), vbCr, ""))
Me.LblD.Text = Trim(Replace(lines(LineGroupCount + 2), vbCr, ""))
Me.LblT.Text = Trim(Replace(lines(LineGroupCount + 3), vbCr, ""))
BtnForward.Enabled = True
CboOne.Enabled = True
End If

Else
MessageBox.Show("You have not yet Saved a File")
End If
End Sub
-------------------------------------


.NET Development11