CopyCode The Code is as follows: using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. text;
Using system. Security. cryptography;
Using system. IO;
Namespace WWW
{
Public partial class jiami: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
BIND ();
}
Private void BIND ()
{
// Encryption
This. Title = desencrypt ("PWD", "abcd1234 ");
This. Title + = desdecrypt (this. title, "abcd1234 ");
Response. Write (desdecrypt ("2ikcw0tqkgo =", "abcd1234 "));
}
/// <Summary>
/// Encrypted string
/// Note: The key must be 8 bits.
/// </Summary>
/// <Param name = "strtext"> string </param>
/// <Param name = "encryptkey"> key </param>
/// <Param name = "encryptkey"> return the encrypted string </param>
Public String desencrypt (string inputstring, string encryptkey)
{
Byte [] bykey = NULL;
Byte [] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
Try
{
Bykey = system. Text. encoding. utf8.getbytes (encryptkey. substring (0, 8 ));
Descryptoserviceprovider des = new descryptoserviceprovider ();
Byte [] inputbytearray = encoding. utf8.getbytes (inputstring );
Memorystream MS = new memorystream ();
Cryptostream cs = new cryptostream (MS, Des. createencryptor (bykey, IV), cryptostreammode. Write );
CS. Write (inputbytearray, 0, inputbytearray. Length );
CS. flushfinalblock ();
Return convert. tobase64string (Ms. toarray ());
}
Catch (system. Exception error)
{
// Return Error. message;
Return NULL;
}
}
/// <Summary>
/// Decrypt the string
/// </Summary>
/// <Param name = "This. inputstring"> encrypted string </param>
/// <Param name = "decryptkey"> key </param>
/// <Param name = "decryptkey"> return the decrypted string </param>
Public String desdecrypt (string inputstring, string decryptkey)
{
Byte [] bykey = NULL;
Byte [] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
Byte [] inputbytearray = new byte [inputstring. Length];
Try
{
Bykey = system. Text. encoding. utf8.getbytes (decryptkey. substring (0, 8 ));
Descryptoserviceprovider des = new descryptoserviceprovider ();
Inputbytearray = convert. frombase64string (inputstring );
Memorystream MS = new memorystream ();
Cryptostream cs = new cryptostream (MS, Des. createdecryptor (bykey, IV), cryptostreammode. Write );
CS. Write (inputbytearray, 0, inputbytearray. Length );
CS. flushfinalblock ();
System. Text. Encoding encoding = new system. Text. utf8encoding ();
Return encoding. getstring (Ms. toarray ());
}
Catch (system. Exception error)
{
// Return Error. message;
Return NULL;
}
}
}
}