CSharpTest.Net
ToByteArray(SecureString,Encoding) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > SecureStringUtils Class > ToByteArray Method : ToByteArray(SecureString,Encoding) Method

data
encoding

Glossary Item Box

Converts a System.Security.SecureString into an array of bytes using the Encoding specified

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function ToByteArray( _
   ByVal data As SecureString, _
   ByVal encoding As Encoding _
) As Byte()
C# 
public static byte[] ToByteArray( 
   SecureString data,
   Encoding encoding
)

Parameters

data
encoding

Example

Library/Library.Test/TestSecureString.cs

C#Copy Code
foreach (SecureString ss in MakeStrings())
{
    Assert.AreEqual(Encoding.Unicode.GetBytes(TEST_PASSWORD), SecureStringUtils.ToByteArray(ss));
    Assert.AreEqual(Encoding.UTF8.GetBytes(TEST_PASSWORD), SecureStringUtils.ToByteArray(ss, Encoding.UTF8));
}
VB.NETCopy Code
For Each ss As SecureString In MakeStrings()
    Assert.AreEqual(Encoding.Unicode.GetBytes(TEST_PASSWORD), SecureStringUtils.ToByteArray(ss))
    Assert.AreEqual(Encoding.UTF8.GetBytes(TEST_PASSWORD), SecureStringUtils.ToByteArray(ss, Encoding.UTF8))
Next

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys