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

K

Kevin Hodgson

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
 
J

Jeff Johnson [MVP: VB]

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?

After you run it through your encryption routine of choice (a two-way
routine, of course), just base-64 encode the results (see the System.Text
namespace for the Encoding class). Then you'll have normal text that you can
stick in the XML file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top