. NET provides a variety of encryption and decryption functions, but only one is used here.
Public class stringdeprovider
{
# Region internal fields
Private ‑ricalgorithm MCSP;
/// <Summary>
/// Key | Note: The length must be 12
/// </Summary>
Private const string CIV = "moliqingcha = ";
/// <Summary>
/// Initialization vector | Note: The length must be 12
/// </Summary>
Private const string ckey = "xingmai0216 = ";
# Endregion
# Region instance Constructor
Public stringdeprovider ()
{
MCSP = new descryptoserviceprovider ();
}
# Endregion
# Region instance method
///
// encrypted string
///
///
//
Public String encryptstring (string value)
{< br> icryptotransform CT;
memorystream MS;
cryptostream Cs;
byte [] BYT;
Ct = MCSP. createencryptor (convert. frombase64string (ckey), convert. frombase64string (CIV ));
Byt = encoding. utf8.getbytes (value );
MS = new memorystream ();
Cs = new cryptostream (MS, CT, cryptostreammode. Write );
CS. Write (BYT, 0, byt. Length );
CS. flushfinalblock ();
CS. Close ();
Return convert. tobase64string (Ms. toarray ());
}
///
// decrypt the string
///
///
//
Public String decryptstring (string value)
{< br> icryptotransform CT;
memorystream MS;
cryptostream Cs;
byte [] BYT;
Ct = MCSP. createdecryptor (convert. frombase64string (ckey), convert. frombase64string (CIV ));
Byt = convert. frombase64string (value );
MS = new memorystream ();
Cs = new cryptostream (MS, CT, cryptostreammode. Write );
CS. Write (BYT, 0, byt. Length );
CS. flushfinalblock ();
CS. Close ();
Return encoding. utf8.getstring (Ms. toarray ());
}
# Endregion
}