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.
/// summary> public class desencryptor {#Region private member /// /// input string /// summary> private string infutstring = null; /// /// output String /// summary> private string outstring = null; /// /// Enter file path /// summary> prince security infutfilepath = null; /// /// output File path /// summary> private string outfilepath = null; /// /// encryption key /// summary> private string encryptkey = null; /// /// Decryption Key /// summary> priz; /// /// Tip information /// summary> private string NoteMessage = NULL; #ENDREGON #REGON public property /// /// Enter String /// summary> public string infutstring {get {return infutstring;} set {infutstring = value;}} /// /// output string /// summary > Public string outstring {get {return = value;}} /// /// Enter file path /// summary> public string infutfilepath {get {return infuntfilepath;} set { InputFilePath = Value;}} // / /// Output file path /// summary> public string outfilepath {get {return outfilepath;} set {outfilepath = value;}} /// /// encryption key /// summary> public string encryptKey {get {return encryptKey;} set {encryptKey = value;}} /// /// decryption key /// summary> public string decryptKey {get {return decryptKey; } Set {decryptkey = value;}} /// /// error message /// summary> 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 param> /// key param > 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 /// summary> /// Add a dense string param> /// Source file path parame> /// key param> 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 /// summary> /// encrypted file path param> /// Output file path param> /// key param> 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;