How to set value of SecureString?

  • Thread starter Thread starter Dean Slindee
  • Start date Start date
D

Dean Slindee

How do you set the value of a Security.SecureString?

Dim strSecure As New Security.SecureString

strSecure = CType("Friday", Security.SecureString)
 
It's not very easy. Here is some code:

Public Shared Function LoadSecureString(ByVal input As String) As
System.Security.SecureString
LoadSecureString = Nothing

If Not String.IsNullOrEmpty(input) Then
LoadSecureString = New System.Security.SecureString
For Each character As Char In input.ToCharArray
LoadSecureString.AppendChar(character)
Next
LoadSecureString.MakeReadOnly()
End If

End Function

======================================
David McCarter [Microsoft VB.NET MVP]
www.vsdntips.com
VSDN Tips & Tricks .NET Coding Standards available at:
www.cafepress.com/vsdntips.20412485
 
Back
Top