CSharpTest.Net
ToArray Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > AESCryptoKey Class : ToArray Method

Glossary Item Box

Serializes the KEY and IV to a single array of bytes. Use FromByteArray() to restore.

Syntax

Visual Basic (Declaration) 
Public Function ToArray() As Byte()
C# 
public byte[] ToArray()

Example

Library/Library.Test/TestEncryption.cs

C#Copy Code
byte[] ivrandom = new byte[16];
new Random().NextBytes(ivrandom);

using (AESCryptoKey k1 = new AESCryptoKey())
using (AESCryptoKey k2 = AESCryptoKey.FromBytes(k1.ToArray()))
{
    Assert.AreEqual(k1.Key, k2.Key);
    Assert.AreEqual(k1.IV, k2.IV);
}
VB.NETCopy Code
Dim ivrandom As Byte() = New Byte(16) {}
New Random().NextBytes(ivrandom)

Using k1 As New AESCryptoKey()
    Using k2 As AESCryptoKey = AESCryptoKey.FromBytes(k1.ToArray())
        Assert.AreEqual(k1.Key, k2.Key)
        Assert.AreEqual(k1.IV, k2.IV)
    End Using
End Using

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys