By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Kevin Hodgson" <ke***@caseware.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
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.
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.