Skip to main content

Read An Encrypted File In Visual Basic

There are many ways to decrypt encrypted text or data. In this tutorial, I'm using DESCryptoServiceProvider class to encrypt and decrypt strings using the cryptographic service provider version of the Triple Data Encryption Standard algorithm.

The use encryption to protect secret data and to make data unreadable by unauthorized users.

In this tutorial I'm going to use the existing project from the previous tutorial Write An Encrypted Text File. Check this tutorial to see how to write an encrypted text file. And today I will modify the previous tutorial and add a methods to read an encrypted file.



Procedure

  1. Download the previous project at Write An Encrypted Text File.
  2. Rename the project to ReadEncryptedFileVB.
  3. Load the project and open the FormMain then add new CommandButton and set the name property to ButtonReadFile and set the text property to Read Encrypted File. Resize the button to display the text property. Set the ButtonWrite text property to Write Encrypted File and resize to display the text property.
  4. Double click the Read Encrypted File button to view the Click event method and paste the code below.

  5.  1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    Using OpenFile As New OpenFileDialog

    With OpenFile
    'Create InitialDirectory variable and get the My Documents folder path
    Dim InitialDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

    'Set the initial directory
    .InitialDirectory = InitialDirectory

    'Set the file extention to filter
    .Filter = "Text files (*.txt)|*.txt;"

    'Set the restore directory
    .RestoreDirectory = True

    If .ShowDialog = DialogResult.OK Then

    Using TextStreamReader As StreamReader = New StreamReader(.FileName)

    TextBoxContainer.Text = EncryptionWrapper.DecryptData(TextStreamReader.ReadToEnd())

    TextStreamReader.Close()

    End Using

    Else

    'If Cancel button was click then
    'Do nothing

    End If

    End With

    End Using

  6. Run the project.
Save the this project for the future tutorials and  that's all. I hope that you enjoy my tutorials.
Subscribe to this page for more


Comments

Popular posts from this blog

Micom SE Studio1 Import Filter - Creating User Interface (UI)

Welcome to my page and welcome to the continuation of Omicron Import Filter tutorial series. In this tutorial, I will show you how to create the actual import filter fom Micom relays. In this tutorial, we will focus on the Visual Studio program. We're going to modify the codes in our project called MyImportFilter that we've created in the previous tutorial.  Download the project in this link  MyImportFilter - Process Relay Setting Parameters . Extract and open the project. Once the project is loaded, add New Folder inside the project and set the name to SEStudio1. We need this to make organize our project class filter.  SE Studio 1 stands for Schneider Electric Studio 1 which is the software that used in communicating MiCOM relays particularly P12x series. And yes we're going to create a new import filter and user interface form MiCOM P12x series relay. I think this will applied to other MiCOM P series relay. Add a new Form inside the  SEStudio1 folder...

Change Data With Feedback In Omicron Control Center Custom Dialog

Welcome to the fifth and final part of the tutorial series about Omicron Control Center (OCC) Custom Dialog. In this tutorial, I will show you how to get a real-time feedback when data was change. This will be helpful that you will be notified what will be the outcome of the changed data. Check the video below. Now, open the OCC document that we used in the previous tutorial. If you don't have it check this link ( Omicron Control Center Custom Dialog - Creating Custom Dialog With Dropdown Control ) then come back here once you have OCC document. When the document is loaded, open the script view by clicking the Script View button under the View tab then stop the script if its running. Now, find the  SetTheSourceController sub procedure. We're going to modify this codes and use different methods of loading data from the test object and saving back to test object. Point the mouse pointer and click between  Begin Dialog and  End Dialog then click the Edit Dialog button un...

Processing The Relay Setting Parameters In Omicron Import Filter

Welcome to my page and welcome to the fifth part of Omicron Import Filter tutorial series. In this tutorial, I will show you how to process the relay setting parameters that to be import in the Xrio converter. In this tutorial, we will focus on the Visual Studio program. We're going to modify the codes in our project called MyImportFilter that we've created in the previous tutorial.  Download the project in this link  MyImportFilter - Process Relay Setting Parameters . Extract and open the project. Once the project is loaded, add New Folder inside the project and set the name to SEStudio1. We need this to make organize our project class filter.  SE Studio 1 stands for Schneider Electric Studio 1 which is the software that used in communicating MiCOM relays particularly P12x series. And yes we're going to create a new import filter and user interface form MiCOM P12x series relay. I think this will applied to other MiCOM P series relay. Add a new Form inside ...