Data encryption with C # (1) - symmetrical encryption algorithm

zhaozj2021-02-16  59

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 / /// public class symmetricmeth {private symmetricmethm mobjcryptoService; private string key; /// // Symmetric encryption class constructor /// public SymmetricMethod () {mobjCryptoService = new RijndaelManaged (); Key = "Guz (% & hj7x89H $ yuBI0456FtmaT5 & fvHUFCy76 * h% (HilJ $ lhj y6 & (* jkP87jH7!";} /// / // Get key /// /// key 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 /// /// 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 /// /// String /// encrypted skewers public string encrypto (string source) {byte [] bytin = utf8encoding.utf8.getbytes (SOURCE);

转载请注明原文地址:https://www.9cbs.com/read-24827.html

New Post(0)