Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Security.Cryptography;
Using System.Configuration;
Namespace Pdf_test
{
public class De_entrypt
{
private static string Rz_key = "ZY HJ 2015";
#region Encrypt encryption
<summary>
Encryption
</summary>
<param name= "Text" ></param>
<returns></returns>
public static string Encrypt (String Text)
{
Return Encrypt (Text, Rz_key);
}
<summary>
Encrypt data
</summary>
<param name= "Text" ></param>
<param name= "SKey" ></param>
<returns></returns>
public static string Encrypt (String Text, String SKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
Byte[] Inputbytearray;
Inputbytearray = Encoding.Default.GetBytes (Text);
Des. Key = ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile ( SKey, "MD5"). Substring (0, 8));
DES.IV = ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (SKey, "MD5"). Substring (0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
CryptoStream cs = new CryptoStream (MS, Des. CreateEncryptor (), cryptostreammode.write);
Cs. Write (Inputbytearray, 0, inputbytearray.length);
Cs. FlushFinalBlock ();
StringBuilder ret = new StringBuilder ();
foreach (Byte b in Ms. ToArray ())
{
Ret. AppendFormat ("{0:x2}", b);
}
return ret. ToString ();
}
#endregion
#region Encrypt decryption
<summary>
Decrypt
</summary>
<param name= "Text" ></param>
<returns></returns>
public static string Decrypt (String Text)
{
Return Decrypt (Text, Rz_key);
}
<summary>
Decrypt data
</summary>
<param name= "Text" ></param>
<param name= "SKey" ></param>
<returns></returns>
public static string Decrypt (String Text, String SKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
int Len;
len = TEXT.LENGTH/2;
byte[] Inputbytearray = new Byte[len];
int x, I;
for (x = 0; x < len; + x)
{
i = Convert.ToInt32 (text.substring (x * 2, 2), 16);
INPUTBYTEARRAY[X] = (byte) i;
}
Des. Key = ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile ( SKey, "MD5"). Substring (0, 8));
DES.IV = ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (SKey, "MD5"). Substring (0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
CryptoStream cs = new CryptoStream (MS, Des. CreateDecryptor (), cryptostreammode.write);
Cs. Write (Inputbytearray, 0, inputbytearray.length);
Cs. FlushFinalBlock ();
Return Encoding.Default.GetString (Ms. ToArray ());
}
#endregion
}
}
C # Cryptographic decryption