Several symmetric encryption algorithms have been integrated in .NET, they can build their own encryption programs soon.
Class used to encrypt in .NET
tabindex = "0" keywords = "frlrfSystemSecurityCryptographyDESCryptoServiceProviderClassTopic" /> DESCryptoServiceProvider tabindex = "0" keywords = "frlrfSystemSecurityCryptographyRC2CryptoServiceProviderClassTopic" /> RC2CryptoServiceProvider tabindex = "0" keywords = "frlrfSystemSecurityCryptographyRijndaelManagedClassTopic" /> RijndaelManaged tabindex = "0" keywords = "frlrfSystemSecurityCryptographyTripleDESCryptoServiceProviderClassTopic" / > TripleDescryptoServiceProvider The following is the encrypted program I have built to note that each encryption algorithm is different for the length of the key and the initial vector, the encryption class is used system; use system.security.cryptography; namespace encryption {/// < summary> /// conversion decryption /// summary> public class DecryptTransformer {internal DecryptTransformer (EncryptionAlgorithm deCryptId) {algorithmID = deCryptId;} private EncryptionAlgorithm algorithmID; private byte [] initVec; internal byte [] IV {set {this. INITVEC = value;}}} ///
} Case EncryptionAlgorithm.Rc2: {RC2 rc2 = new RC2CryptoServiceProvider (); rc2.Mode = CipherMode.CBC; return rc2.CreateDecryptor (bytesKey, initVec);} case EncryptionAlgorithm.Rijndael: {Rijndael rijndael = new RijndaelManaged (); rijndael. Mode = CipherMode.CBC; return rijndael.CreateDecryptor (bytesKey, initVec);} default: {throw new CryptographicException ( "Algorithm ID '" algorithmID "' not supported");}}}}} using System; using System.Security .Cryptography; Namespace Encryption {///
} // The following settings The initialization vector if (null == initVec) {INITVEC = des.iv;} else {des.iv = initVec;} // Return a cryptometer Return DES.CREATEENCRYPTOR ();} Case EncryptionAlgorithm.tripledes: {TripLeDes Des3 = New TripleDescryptoServiceProvider (); des3.mode = cophermode.cbc; // Setting key IF (null == byteskey) {eLse = des3.key;} else {des3.key = byteskey; this.enckey = des3 K} // Setting the initialization vector if (null == initVec) {initVec = des3.IV;} else {des3.IV = initVec;} // Return the encrypler Return des3.createEncryptor ();} case encryptionalgorithm.RC2 : {// Initialization Encryption Service RC2 RC2 = New RC2cryptoserviceProvider (); rc2.mode = cophermode.cbc; // Setting Key IF (NULL == Byteskey) {eNCKEY = RC2.Key;} else {rc2.key = byteskey This.Enckey = rc2.key;} // Set the initialization vector if (null == initVec) {initVec = rc2.iv;} else {rc2.iv = initVec;} // Return to the encryprators return Return rc2.CreateEncryptor ();} case EncryptionAlgorithm.Rijndael: {Rijndael rijndael = new RijndaelManaged (); rijndael.Mode = CipherMode.CBC; // key set if (null == bytesKey) {encKey = rijndael.Key;} else {Rijndael.key = byteskey; this.Enckey = rijndael.key;} // sets the initialization vector if (null == initVec) {initVec = rijndael.iv;} else {rijndael.iv = initVec;} // Return Enterprise Return rijndael.createEncryptor ();} default: {throw new cryptographicException ("Algorithm ID '" Algorithmid "'
NOT Supported. ");}}}}}}}}}}}}}}}} Using system; use system.io; use system.security.cryptography; namespace encryption {///
Public Byte [] iv {get {Return INITVEC;}}} public byte [] key {get {return enckey;}} ///
/ summary> /// Deciplive file path param> /// Output file path param> /// password param> ///
/// Construct a file encryption class /// //// an enumeration, used to define encryption methods param> public fileEncryptor (encryptionalgorithm algid) {this.transformer = New encrypttransformer (algid);} private encrypttransformer transformer; private botte [] initVec; private bote [] enckey; ///
// if you do not give a key then will create a key automaticlly CryptoStream encStream = new CryptoStream (fout, transform, CryptoStreamMode.Write); Console.WriteLine ( "Encrypting ..."); while (rdlen
/// summary> [stathread] static void main (String [] args) {message ("This is a program that encrypts and decrypts, using symmetric encryption technology, uses DES, 3DES, RS2, RIJNDAEL encryption algorithm!" ); Message ("follow the prompts to complete the operation! (Note that the length of the key and the initial vector"); Message ("@ 2005 ---- Pan Weifeng"); int action = 0; string infile = Null; string outfile = null; string password = null; string IV = null; int encryptedMethod = 0; byte [] key = null; byte [] IV = null; if (args.length == 4) {action = convert. TOINT32 (Args [0] .trim ()); infile = args [1]; outfile = args [2]; password = args [3]; EncryptedMethod = Convert.Toint32 (Args [4] .trim ());} While (action == 0 || infile == null || outfile == null || PASSWORD == NULL || iv == null || encryptedMethod == 0) {if (action == 0) {Console.WriteLine "Please select an action"); console.writeline ("1. Encrypted a file"); console.writeline ("2. Decrypt a file"); action = convert.Toint32 (console.readline (). Trim ()) } If (infile == null) {if (action == 1) {console.writeline ("Please enter the file path you want to encrypted");} if (action == 2) {Console.WriteLine ("Please enter You have to decrypt the file path "); } Infile = console.readline (). Trim (); fileinfo f = new fileInfo (infile); if (! F.exists) {console.writeline ("file does not exist"); infile = null; continue;}}} (outfile == null) {if (action == 1) {console.writeLine ("Please enter the encrypted file storage path");} if (action == 2) {console.writeLine ("Please enter the decrypted file Storage path ");} outfile = console.readline (). Trim ();} if (encryptedMethod ==
0) {Console.Writeline ("Please select an encryption algorithm:"); console.writeline ("1.des"); console.writeLine ("2.RC2"); console.writeLine ("3.rijndael"); Console.writeline ("4.tripledes"); EncryptedMethod = Convert.Toint32 (). Trim ());} if (password == null) {Console.WriteLine ("Please enter your password:"); showRightKeysize (EncryptedMethod); Password = console.readline (). Trim ();} if (iv == null) {Console.Writeline ("Please enter the initial vector:"); console.writeline ("Note: The initial vector must correct "); ShowRightIVSize (encryptedmethod); iv = Console.ReadLine () Trim ();}} // choose a Encrypted Mehod EncryptionAlgorithm algorithm; switch (encryptedmethod) {case 1:. {algorithm = EncryptionAlgorithm.Des; break;} case 2: {algorithm = EncryptionAlgorithm.Rc2; break;} case 3: {algorithm = EncryptionAlgorithm.Rijndael; break;} case 4: {algorithm = EncryptionAlgorithm.TripleDes; break;} default: {algorithm = Encrypt Ionalgorithm.des; break;}} iv = encoding.ascii.getbytes (iv); key = encoding.ascii.getBytes (password); if (action == 1) {FileEncryptor Fe = New FileEncryptor (algorithm); // define A New FileEncryptor Acording to the EncryptorMethod Fe.IV = IV; IF (Fe.EncryptFile (Infile, Outfile, Key)) {Console.WriteLine ("Encryption Success"); console.readline ();}} f (action == 2) {FileDecryptor FD = New FileDecryptor (Algorithm); fd.iv = iv; if (fd.decryptfile (infile, outfile, key)) {console.writeline ("Decryption success"); console.readline ();