[Adapdev-commits] Adapdev/src/Adapdev.Tests/Cryptography CryptoTest.cs,1.3,1.4
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:02:12
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Tests/Cryptography In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Tests/Cryptography Added Files: CryptoTest.cs Log Message: --- NEW FILE: CryptoTest.cs --- using System; using System.Text; using Adapdev.Cryptography; using NUnit.Framework; namespace Adapdev.Cryptography.Tests { /// <summary> /// Summary description for Encryptor. /// </summary> /// [TestFixture] public class CryptoTest { private string _text = "This is the text to encrypt"; // Des private string _password8 = "password"; // Rijndael / TripleDes private string _password16 = "password12345678"; // Des / TripleDes private string _vector8 = "init vec"; // Rijndael private string _vector16 = "init vec is big."; [Test] public void EncryptDecryptDes() { this.EncryptDecrypt(this._password8, this._vector8, EncryptionAlgorithm.Des); } [Test] public void EncryptDecryptTripleDes() { this.EncryptDecrypt(this._password16, this._vector8, EncryptionAlgorithm.TripleDes); } [Test] public void EncryptDecryptRijndael() { this.EncryptDecrypt(this._password16, this._vector16, EncryptionAlgorithm.Rijndael); } [Test] public void EncryptDecryptDesDefault() { this.EncryptDecrypt(EncryptionAlgorithm.Des); } [Test] public void EncryptDecryptTripleDefault() { this.EncryptDecrypt(EncryptionAlgorithm.TripleDes); } [Test] public void EncryptDecryptRijndaelDefault() { this.EncryptDecrypt(EncryptionAlgorithm.Rijndael); } private void EncryptDecrypt(string key, string vector, EncryptionAlgorithm algorithm) { Console.WriteLine("Processing " + algorithm.ToString()); // Get the encrypted value byte[] cipherText = Crypto.Encrypt(this._text, key, vector, algorithm); // Display it //Console.WriteLine("Encrypted: " + Encoding.ASCII.GetString(cipherText)); // Decrypt string plainText = Crypto.Decrypt(cipherText, key, vector, algorithm); // Display it Console.WriteLine("Decrypted: " + plainText); // Decrypted value should be same as original Assert.AreEqual(this._text, plainText, "Incorrect value decrypted"); } private void EncryptDecrypt(EncryptionAlgorithm algorithm) { Console.WriteLine("Processing " + algorithm.ToString()); // Get the encrypted value using the built in key and vector byte[] cipherText = Crypto.Encrypt(this._text, algorithm); // Display it //Console.WriteLine("Encrypted: " + Encoding.ASCII.GetString(cipherText)); // Get the decrypted value using the built in key and vector string plainText = Crypto.Decrypt(cipherText, algorithm); // Display it Console.WriteLine("Decrypted: " + plainText); // Decrypted value should be same as original Assert.AreEqual(this._text, plainText, "Incorrect value decrypted"); } } } |