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

Glossary Item Box

Used to define the IV for AES keys created in this process, by default this is MD5(UTF8(Name)) where Name is the short-name of either the entry-point assembly, or "CSharpTest.Net.Library" if undefined.

Syntax

Visual Basic (Declaration) 
Public Shared Property ProcessDefaultIV As Byte()
C# 
public static byte[] ProcessDefaultIV {get; set;}

Remarks

The process default IV is used with AESCryptoKey instances that are created without explicitly providing the IV value for the key. This is done internally when using the Password class' CreateKey(...), Encrypt(...), or Decrypt(...) methods. While this worked well enough for some programs, this has proven to be a flawed approach as the entry-point assembly can change. For example if another .NET process call Assembly.Execute() on your executable. Applications are advised that they should capture the existing value and store that in App.Config, and set the following prior to using this class, or the Password class. The entry-points related to this that have been marked Obsolete() will be removed in the long-term and by capturing this value and manually using it you can ensure your application will continue to function properly.

Example

Library/Library.Test/TestEncryption.cs

C#Copy Code
byte[] original = AESCryptoKey.ProcessDefaultIV;
try
{
    Assert.AreEqual(original, new AESCryptoKey().IV);

    byte[] newIv = new byte[16];
    new Random().NextBytes(newIv);
    AESCryptoKey.ProcessDefaultIV = newIv;

    Assert.AreEqual(newIv, AESCryptoKey.ProcessDefaultIV);
    Assert.AreEqual(newIv, new AESCryptoKey().IV);
}
finally
{
    AESCryptoKey.ProcessDefaultIV = original;
}
VB.NETCopy Code
Dim original As Byte() = AESCryptoKey.ProcessDefaultIV
Try
    Assert.AreEqual(original, New AESCryptoKey().IV)

    Dim newIv As Byte() = New Byte(16) {}
    New Random().NextBytes(newIv)
    AESCryptoKey.ProcessDefaultIV = newIv

    Assert.AreEqual(newIv, AESCryptoKey.ProcessDefaultIV)
    Assert.AreEqual(newIv, New AESCryptoKey().IV)
Finally
    AESCryptoKey.ProcessDefaultIV = original
End Try

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys