Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Salt Property
Collapse the table of content
Expand the table of content

Rfc2898DeriveBytes.Salt Property

Gets or sets the key salt value for the operation.

Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)

public byte[] Salt { get; set; }
/** @property */
public byte[] get_Salt ()

/** @property */
public void set_Salt (byte[] value)

public function get Salt () : byte[]

public function set Salt (value : byte[])

Not applicable.

Property Value

The key salt value for the operation.

Exception typeCondition

ArgumentException

The specified salt size is smaller than 8 bytes.

ArgumentNullException

The salt is a null reference (Nothing in Visual Basic).

Salt, a random set of bytes, is used to make unauthorized decrypting of a message more difficult. A dictionary attack is an attack in which the attacker attempts to decrypt an encrypted message by comparing the encrypted value with previously computed encrypted values for the most likely keys. This attack is made much more difficult by the introduction of salt, or random bytes, at the end of the password before the key derivation.

The following code example uses the Rfc2898DeriveBytes class to create two identical keys for the TripleDES class. It then encrypts and decrypts some data using the keys.

string pwd1 = passwordargs[0];

byte[] salt1 = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45};
//data1 can be a string or contents of a file.
string data1 = "Some test data";
//The default iteration count is 1000 so the two methods use the same iteration count.
int myIterations = 1000;

String pwd1 = (String)passwordArgs.get_Item(0);

ubyte salt1[] = new ubyte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6,
    0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };
//data1 can be a string or contents of a file.
String data1 = "Some test data";
//The default iteration count is 1000 so the two methods use the
//same iteration count.
int myIterations = 1000;

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft