Data encryption with C # (1) - symmetrical encryption algorithm
The following is a C # implementation code about the symmetric encryption algorithm. You can change the different algorithms as needed.
Using system; using system.seircurity.cryptography; using system.text;
Namespace Datacrypto {/// // / Symmetric Class Disease Class / /// summary> public class symmetricmeth {private symmetricmethm mobjcryptoService; private string key; /// // Symmetric encryption class constructor /// summary> public SymmetricMethod () {mobjCryptoService = new RijndaelManaged (); Key = "Guz (% & hj7x89H $ yuBI0456FtmaT5 & fvHUFCy76 * h% (HilJ $ lhj y6 & (* jkP87jH7!";} /// / // Get key /// summary> /// key returns> private byte [] getlegalkey () {string step = key; mobjcryptoservice.generateKey (); byte [] byttemp = mobjcryptoservice. Key; int KeyLength = bytTemp.Length; if (sTemp.Length> KeyLength) sTemp = sTemp.Substring (0, KeyLength); else if (sTemp.Length /// Get initial vector IV /// summary> /// PRIVATE BYTE [] getlegaliv () {String Stemp = "E4GHJ * GHG7! RNIFB & 95Guy86GFGHUB # ER57HBH (U% G6HJ ($ JHWK7 &! HG4UI% $ hjk"; MOBJ CryptoService.GenerateIV (); byte [] bytTemp = mobjCryptoService.IV; int IVLength = bytTemp.Length; if (sTemp.Length> IVLength) sTemp = sTemp.Substring (0, IVLength); else if (sTemp.Length /// encryption method /// summary> /// String param> /// encrypted skewers returns> public string encrypto (string source) {byte [] bytin = utf8encoding.utf8.getbytes (SOURCE);