Home > Net >  About DES encryption solution
About DES encryption solution

Time:10-09

On.net DES encryption solution
EDS is a grouping encryption algorithm, through the 64 group to encrypt data, design EDS encryption program
Public static string EncodeDES (string encryptString, string the encryptkey)
{
Try
{
Byte [] rgbkey=encoding. UTF8. Getbytes (the encryptkey. Substring (0, 8));
Byte [] rgbIV=keyIV;
Byte [] inputArray=encoding. UTE8. Getbytes (encryptString);
DESCryptoservicePrvider desCSP=DESCryptoservicePrvider ();
MemoryStream mStream=new MemoryStream ();
CryptoStream cStream=new CryptoStream (mStream, desCSP CreateEncryptor (rgbKey, rgbIV),
CryptoStreamMode. Write);
CSteam. Write (inputArray, 0, inputArray. Length);
CSteam. FlushFinalBlock ()
Return the Convert. ToBase64String (mStream ToArray ());
}
Catch
{
Return encryptString;
}
}
Design decoding program
Public static string DecodeDES (string decryptString, string decryptkey)
{
Try
{
Byte [] rgbkey=Encoding. UTF8. Getbytes (Decryptkey. Substring (0, 8));
Byte [] rgbIV=keyIV;
Byte [] inputArray=encoding. UTE8. Getbytes (decryptString);
DESCryptoservicePrvider desCSP=new DESCryptoservicePrvider ();
MemoryStream mStream=new MemoryStream ();
CryptoStream cStream=new CryptoStream (mStream, desCSP CreateEncryptor (rgbKey, rgbIV),
CryptoStreamMode. Write);
CSteam. Write (inputArray, 0, inputArray. Length);
CSteam. FlushFinalBlock ()
Return the Convert. ToBase64String (mStream ToArray ());
}
Catch
{
Return decryptString;
}
}
For btnEncode add event, realizes the DES encryption
Private viod btnEncode_Click (objiect sender, EventArgs e)
{
StreamRadear datain=File. OpenTxet (tbBeforeCrypFile. Text);
String strTmp;
ArrayList alldate=new ArrayList ();
While ((strTmp=datain ReadLine ())!=null)
{
Alldate. Add (strTmp);
}
The Foreach (string STR in alldate)
{
TbBeforeCrypContent. Text +=STR;
TbBeforeCrypContent. Text +="\ r \ n";
Try
{
String temp=tbBeforeCrypContent. Text;
TbBeforeCrypContent. Text=EncodeDES (temp, keyDes);
}
The Catch (System. Exception ep)
{
MassageBox. Show (ep. Mssage);
}
FileSteam FileSteam=new FileSteam (tbAfterCrypFile. Text, filemode. Openorcreate);
Steamwriter Steamwriter=new Steamwriter (filesteam)
//write
Steamwrite. Write (tbaftercrypcontent. Text);
//to empty the cache
Streamwriter. Flush ();
//off flow
Steamwrite. Close ();
Filesteam. Close ();
}
Add events to btnDecode, realizes the DES declassified
Private viod btndecode_click (object sender, eventargse)
{
Try
{
String temp=tbaftercrypcontent. Text;
Tbaftercrypcontent. Text=decodeDES (temp, keydes);
}
The Catch (System. Exception ep)
{
Massagebox. Show (ep. Massage)
}
}

CodePudding user response:

What are you going to implement, related objects,
  • Related