Use DES, MD5 encryption. Decryption. String. File

xiaoxiao2021-03-05  23

// Encrypted string, pay attention to the length of StrenchKey is 8 bits (if you want to increase or reduce the length length, adjust the length of the IV is) Public String Desencrypt (String StRTEXT, STRING Strencrkey)

// Decrypt string, pay attention to Strench, the length of 8 bits (if you want to increase or reduce the length length, adjust the length of the IV)

Public String Desdecrypt (String STRTEXT, STRING SDECRKEY)

// Encrypted data file, pay attention to the length of Strencrkey (if you want to add or reduce the length length, adjust the length of IV)

Public void desencrypt (string m_infilepath, string m_outfilepath, string strencrkey)

// Decrypt data file, pay attention to StrenchKey length of 8 bits (if you want to increase or reduce the length length, adjust the length of IV)

Public void deSDecrypt (String M_INFILEPATH, STRING M_OUTFILEPATH, STRING SDECRKEY)

// MD5 encryption

Public String Md5encrypt (String Strtext)

* /

/ ************************************************** *************************************************** * CRYPTOGRAPHY CLASS for CRYPTOGRAPHY Author: Jim E_mail: tjq_tang@hotmail.com * Thanks: * URI: * * ******************************************** *********************************************************** **** / using system; using system.security.cryptography; using system.io; using system.windows.form;

Namespace NetBee.Classes.security {///

/// cryptography /// public class cryptography {public cryptography () {

} ///

/// encrypt the string /// attention: key must be 8 bits /// /// string /// < Param name = "strencrkey"> key /// public string desencrypt (string string strencrkey) {byte [] bykey = null; Byte [] iv = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; try {byKey = System.Text.Encoding.UTF8.GetBytes (strEncrKey.Substring (0,8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); byte [] inputByteArray = Encoding.UTF8.GetBytes (strText); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (ms, des.CreateEncryptor (byKey, IV), CryptoStreamMode.Write); cs.Write (inputByteArray, 0, inputByteArray.Length ); cs.flushfinalblock (); return control.tobase64string (ms.toarray ());

} catch (system.exception error) {messagebox.show (error.Message); return "error:" error.Message "/ r";}} ///

/// Decrypt string /// attention: Key Must Be 8 Bits /// /// Decrypt string /// /// encrypt files /// attention: key must be 8 bits //// /// Encrypt File path /// Output file /// key public void deseNcrypt (string m_infilepath, string m_outfilepath, string strencrkey) {byte [] bykey = null; byte [] iv =

{0x12, 0x34, 0x56, 0x78, 0x90, 0xAb, 0xcd, 0xef}; Try {bykey = system.text.Encoding.utf8.getbytes (Strencrkey.substring (0,8)); FILESTREAM FIN = New FileStream (m_infilepath, FileMode.Open, FileAccess.Read); FileStream fout = new FileStream (m_OutFilePath, FileMode.OpenOrCreate, FileAccess.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 = 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

ENCSTream.close (); fout.close (); fin.close ();

} catch (system.exception error) {messagebox.show (Error.Message.toString ());

}}} ///

/// Decrypt files /// Attention: key must be 8 bits /// /// Decrypt filepath /// output filepath /// key public void DesDecrypt (string m_InFilePath, string m_OutFilePath, string sDecrKey) {byte [] byKey = null Byte [] iv = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAb, 0xcd, 0xef}; try {bykey = system.text.encoding.utf8.getbytes (SDECRKE.SUBSTRING (0, 8)); FILESTREAM FIN = new FileStream (m_InFilePath, FileMode.Open, FileAccess.Read); FileStream fout = new FileStream (m_OutFilePath, FileMode.OpenOrCreate, FileAccess.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.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;

// read from the input file, the Encrypt and Write to the output file. While (Rdlen

ENCSTream.close (); fout.close (); fin.close ();

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

New Post(0)