Home > Software engineering >  C # DES encryption to decrypt garbled words
C # DES encryption to decrypt garbled words

Time:10-04

Encryption source code is in the best - experience on c # DES declassified and c # DES encryption
 in the previous chapter "c # how to implement the DES encryption algorithm" to establish the engineering (address is: http://jingyan.baidu.com/article/c910274bc6f50bcd371d2d10.html), on the basis of the class file EncryptDES. Cs to add the following method: 
///& lt; Summary>
///DES declassified string
///& lt;/summary>
///& lt; Param name="decryptString & gt;" To decrypt the string & lt;/param>
///& lt; Param name="decryptKey & gt;" Decryption key, for eight, and the same encryption key & lt;/param>
///& lt; Returns> Decryption successfully returns decrypted string, failure to return the source string & lt;/returns>
Public static string DecryptDES (string decryptString, string decryptKey)
{
Try
{
Byte [] rgbKey=Encoding. UTF8. GetBytes (decryptKey. Substring (0, 8));
//rgbIV unlike rgbKey can, here only to simple, readers can modify
Byte [] rgbIV=Encoding. UTF8. GetBytes (decryptKey. Substring (0, 8));
Byte [] inputByteArray=the Convert. FromBase64String (decryptString);
DESCryptoServiceProvider DCSP=new DESCryptoServiceProvider ();
MemoryStream mStream=new MemoryStream ();
CryptoStream cStream=new CryptoStream (mStream, DCSP CreateDecryptor (rgbKey, rgbIV), CryptoStreamMode. Write);
CStream. Write (inputByteArray, 0, inputByteArray. Length);
CStream. FlushFinalBlock ();
Return. Encoding UTF8. Get string (mStream ToArray ());
}
The catch (Exception ex)
{
Return decryptString;
}
}

Double-click the button, enter the code editor interface, add the following code, as shown in figure,
String en="how to implement the DES encryption algorithm c #";
The string result=EncryptDES. StrEncryptDES (en, "hello, I am bianyuanhuanghun");
MessageBox. Show (result);


The question now is can decrypt but after tests found the first 3 characters (six characters) will be garbled words behind all
Case below


Encrypted password: codeexam
Cipher: RuZFkVLbyIdjn02U0zCeuNod4enfBR4rjJawFgPdEC74q56fmE9kXU9umGF6MGVTr9tq5d5JpRRMU + D2M3gxbOgfJnCHeDKD
Decryption:} DJ1 form, validity is second only to the constitution (),
Correct decryption: the following method to form, validity is second only to the constitution (),

Help take a look at the code is how to return a responsibility!

CodePudding user response:

The meaning of encrypted password is the key?

CodePudding user response:

Search "BOM"?

CodePudding user response:

You test process is wrong, it seems like there are base 64 participated in, with full 00, first of all, 00 encryption results in memory view, should be

//3 des_encode_ecb (,)
//- triple des encrypt the ECB
//- key=00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//-- plain=00 00 00 00 00 00 00 00 cipher=8 c A6 4 d E9 C1 B1 23 A7
//
//-- -- -- -- -- the Final result - 8 c A6 4 d E9 C1 B1 23 A7
//
  • Related