Need to encrypt a string and store it in aN XML File.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Kevin Hodgson (kevin_at_caseware.com)
Date: 10/04/04


Date: Mon, 4 Oct 2004 14:22:08 -0400

I store a users SMTP UserName and Password in a settings class, which is
serialized to an XML Settings File.

I need to encrypt the password string in some manner. Does anyone have any
ideas how to do that and still store it in the XML File?
I was thinking of putting the Encryption/Decryption code in the Get/Set
methods of the SMTPPassword Property.

Sample Code:

    Public Sub Persist()
        '// Save the Settings object to XML Files
        Dim settingsPath As String =
IO.Path.Combine(Application.UserAppDataPath, "settings.xml")
        Dim myXMLSerializer As Xml.Serialization.XmlSerializer
        Dim settingsFile As IO.StreamWriter

        '//Save the settings class
        myXMLSerializer = New
Xml.Serialization.XmlSerializer(GetType(Settings))
        settingsFile = New IO.StreamWriter(settingsPath)
        myXMLSerializer.Serialize(settingsFile, appSettings)
        settingsFile.Close()
    End Sub

<Serializable()> Public Class Settings
    Dim m_SMTPLoginName as String
    Dim m_SMTPPassword as String
    Public Property SMTPLoginName() as String
        Get
            Return m_SMTPLoginName
        End Get
        Set(ByVal Value As String)
            m_SMTPLoginName = Value
        End Set
    End Property
    Public Property SMTPPassword() as String
        Get
            Return m_SMTPPassword
        End Get
        Set(ByVal Value As String)
            m_SMTPPassword = Value
        End Set
    End Property
End Class



Relevant Pages

  • Re: Deployment + Vista
    ... The problem is it's connection string is always hard ... Server settings form. ... guess it's a good thing I do not use that for settings. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Calculations on activex components using IUSR
    ... After doing the calculations on my values the value is converted to string ... When converting the value to string it contains a comma instead of period. ... and doesn't change its locale settings ...
    (microsoft.public.vb.com)
  • Re: Whats best practice using dynamic connections strings
    ... the string from the Settings file to get it from this other mechanism. ... I felt this was a shortcoming of the Data Designer, ... where it will read the connection string from. ...
    (microsoft.public.vsnet.general)
  • Re: tables
    ... bypass excel altogether and have the data within the application ... Just because you were using Excel before, that doesn't mean that the data needs to be in any sort of Excel-like object when it's entirely contained within the application. ... As far as saving goes, you have a variety of options, but one of the simplest is to put the data in your applications settings and use the Properties.Settings.Default class to read and write them. ... The array of doubles won't automatically serialize, so probably the best thing to do there is write some custom code that writes to a StringWriter based on a StringBuilder, and then save the resulting string in the application settings. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: VB6 and Windows Media Player
    ... within the My Music Folder. ... Private Declare Function ShellExecute Lib "shell32.dll" Alias ... "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal ... the folder Documents and Settings eg:- C:\Documents and Settings? ...
    (microsoft.public.vb.general.discussion)