Encryption and decryption

xiaoxiao2021-03-06  150

This class is that I have a summary of several documents online. I can use it directly. After a piece of MD5, I should be independent as a class, I am lazy, so I will write a file when I test. Still full, if there is any confidential file, use this thing to deal with it, it will be handled in the future, just don't forget the password, if you are as lazy as me, you directly Code copying directly. Using system; use system.text; using system.security.cryptography; using system.web; Namespace Test.com {///

/// desencryptor's summary description.

/// public class desencryptor {#Region private member ///

/// input string /// private string infutstring = null; /// /// output String /// private string outstring = null; /// /// Enter file path /// prince security infutfilepath = null; /// /// output File path /// private string outfilepath = null; /// /// encryption key /// private string encryptkey = null; /// /// Decryption Key /// priz; /// /// Tip information /// private string NoteMessage = NULL; #ENDREGON #REGON public property /// /// Enter String /// public string infutstring {get {return infutstring;} set {infutstring = value;}} /// /// output string /// Public string outstring {get {return = value;}} /// /// Enter file path /// public string infutfilepath {get {return infuntfilepath;} set { InputFilePath = Value;}} // / /// Output file path /// public string outfilepath {get {return outfilepath;} set {outfilepath = value;}} /// /// encryption key /// public string encryptKey {get {return encryptKey;} set {encryptKey = value;}} /// /// decryption key /// public string decryptKey {get {return decryptKey; } Set {decryptkey = value;}} /// /// error message /// public string NoteMessage {get {return NoteMessage;} set {NoteMessage = VALUE

}} #Endregion #region constructor PUBLIC DESENCRYPTOR () {// // Todo: Add Construction Function Logic //} #ENDREGON #Region DES Encrypted string ///

/// encryption string / // Note: The key must be 8 bits /// string /// key Public void desencrypt () {byte [] bykey = null; byte [] iv = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAb, 0xcd, 0xef}; try {bykey = system.text.encoding.utf8.Getbytes CryptoStream CryptoStream cs = new; (this.encryptKey.Substring (0,8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); byte [] inputByteArray = Encoding.UTF8.GetBytes (this.inputString); MemoryStream ms = new MemoryStream () (ms, des.CreateEncryptor (byKey, IV), CryptoStreamMode.Write); cs.Write (inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock (); this.outString = Convert.ToBase64String (ms.ToArray ()) ;} Catch (system.exception error) {this.noteMessage = error.Message;}} #endregion #region DES decryption string /// < Summary> /// Decryption string /// /// Add a dense string /// Source file path /// key public void filedeenderpt () {byte [] bykey = null; Byte [] iv = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAb, 0xcd, 0xef}; try {bykey = system.text.encoding.utf8.getbytes (this.encryptkey.substring (0,8)); filestream fin = new filestream (this.inputfilepath FileMode.open, FileAccess.read; FileStream Fout = New FileStream (this.Outfilepath, FileMode.Openorcreate, FileAcces S.Write); Fout.setlength (0); // Create Variables to help with read and write. byte [] bin = new byte [100]; // this is interface for the encryption. long rdlen = 0; / / This is the total number of bytes Written. Long Totlen = FIN.LENGTH; // this is the total length of the input file. Int LEN; // this is the number of bytes to be Written at a time. Des des des- New DescryptoServiceProvider (); Cryptostream EncStream = New CryptostReam (Fout, Des.createEncryptor (bykey, IV), CryptostreamMode.write;

// read from the input file, the Encrypt and Write to the output file. While (Rdlen /// Decryption file /// /// encrypted file path /// Output file path /// key public void filedecrypt () {byte [] bykey = null; Byte [] iv = {0x12 , 0x34, 0x56, 0x78, 0x90, 0xAb, 0xcd, 0xef}; try {bykey = system.text.Encoding.utf8.getbytes (DecryptKey.Substring (0, 8)); FILESTREAM FIN = New FileStream (this.inputFilepath, FileMode.open, FileAccess.read; filestream fout = new filestream (this.Outfilepath, filemode.openorcreate, flyaccess.write); fout.setlength (0); // Create variables to help with read and write. Byte [] bin = new byte [100]; // this is intermediate storage for the encryption. Long rdlen = 0; // this is the total number of bytes Written. Long Totlen = FIN. LONG TOTLEN = FIN .Length; // This is the total length of the input file int len;. // This is the number of bytes to be written at a time dES des = new DESCryptoServiceProvider ();. CryptoStream encStream = new CryptoStream (fout, des .Createdecryptor (bykey, iv), cryptostreammode.write;

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

New Post(0)