RC2CryptoServiceProvider::UseSalt Property
Gets or sets a value that determines whether to create a key with an 11-byte-long, zero-value salt.
Assembly: mscorlib (in mscorlib.dll)
public: [ComVisibleAttribute(false)] property bool UseSalt { bool get(); void set(bool value); }
Property Value
Type: System::Booleantrue if the key should be created with an 11-byte-long, zero-value salt; otherwise, false. The default is false.
The UseSalt property allows you to interoperate with an existing application that uses an 11-byte-long, zero-value salt. For most scenarios, you should not use a salt with an RC2CryptoServiceProvider key.
The following code example sets the UseSalt property to true, and then encrypts and decrypts a value.
using namespace System; using namespace System::IO; using namespace System::Text; using namespace System::Security::Cryptography; int main() { array <Byte>^ originalBytes = ASCIIEncoding::ASCII->GetBytes("Here is some data."); //Create a new RC2CryptoServiceProvider. RC2CryptoServiceProvider^ rc2Provider = gcnew RC2CryptoServiceProvider(); rc2Provider->UseSalt = true; rc2Provider->GenerateKey(); rc2Provider->GenerateIV(); //Encrypt the data. MemoryStream^ encryptionMemoryStream = gcnew MemoryStream(); CryptoStream^ encryptionCryptoStream = gcnew CryptoStream( encryptionMemoryStream, rc2Provider->CreateEncryptor( rc2Provider->Key, rc2Provider->IV), CryptoStreamMode::Write); //Write all data to the crypto stream and flush it. encryptionCryptoStream->Write(originalBytes, 0, originalBytes->Length); encryptionCryptoStream->FlushFinalBlock(); //Get encrypted array of bytes. array<Byte>^ encryptedBytes = encryptionMemoryStream->ToArray(); //Decrypt the previously encrypted message. MemoryStream^ decryptionMemoryStream = gcnew MemoryStream(encryptedBytes); CryptoStream^ decryptionCryptoStream = gcnew CryptoStream(decryptionMemoryStream, rc2Provider->CreateDecryptor(rc2Provider->Key,rc2Provider->IV), CryptoStreamMode::Read); array<Byte>^ unencryptedBytes = gcnew array<Byte>(originalBytes->Length); //Read the data out of the crypto stream. decryptionCryptoStream->Read(unencryptedBytes, 0, unencryptedBytes->Length); //Convert the byte array back into a string. String^ plainText = ASCIIEncoding::ASCII->GetString(unencryptedBytes); //Display the results. Console::WriteLine("Unencrypted text: {0}", plainText); Console::ReadLine(); }
Available since 2.0