/// <span class="code-SummaryComment"><summary></span>
/// Encrypt a string.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="originalString">The original string.</param></span>
/// <span class="code-SummaryComment"><returns>The encrypted string.</returns></span>
/// <span class="code-SummaryComment"><exception cref="ArgumentNullException">This exception will be </span>
/// thrown when the original string is null or empty.<span class="code-SummaryComment"></exception></span>
public static string Encrypt(string originalString)
{
if (String.IsNullOrEmpty(originalString))
{
throw new ArgumentNullException
("The string which needs to be encrypted can not be null.");
}
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream,
cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
StreamWriter writer = new StreamWriter(cryptoStream);
writer.Write(originalString);
writer.Flush();
cryptoStream.FlushFinalBlock();
writer.Flush();
return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
}