/// <Summary>
/// Use base64 Algorithm Encryption
/// </Summary>
/// <Param name = "code_type"> encoding type (encoding name)
///* Code Page name
// * 1200 "UTF-16LE", "UTF-16", "ucs-2", "Unicode", or "ISO-10646-UCS-2"
/// * 1201 "UTF-16BE" or "unicodefffe"
/// * 1252 "Windows-1252"
// * 65000 "utf-7", "csunicode11utf7", "unicode-1-1-utf-7", "unicode-2-0-utf-7", "x-unicode-1-1-utf-7" or "x-unicode-2-0-utf-7"
// * 65001 "UTF-8", "unicode-1-1-utf-8", "unicode-2-0-utf-8", "x-unicode-1-1-utf-8" or "x-unicode-2-0-utf-8"
/// * 20127 "US-ASCII", "us", "ASCII", "ANSI_X3.4-1968", "ANSI_X3.4-1986", "cp367", "csascii", "ibm367 "," iso-ir-6 "," ISO646-US "or" iso_646.irv: 1991"
/// * 54936 "gb18030"
/// </Param>
/// <Param name = "code"> string to be encrypted </param>
/// <Returns> encrypted string </returns>
Public String encodebase64 (string code_type, string code)
{
String encode = "";
Byte [] bytes = encoding. getencoding (code_type). getbytes (CODE); // encode a group of characters into a byte sequence.
Try
{
Encode = convert. tobase64string (bytes); // converts a subset of an 8-bit unsigned integer array to an equivalent string encoded in 64-bit notation.
}
Catch
{
Encode = code;
}
Return encode;
}
/// <Summary>
/// Use base64 to decrypt the string
/// </Summary>
/// <Param name = "code_type"> encoding type </param>
/// <Param name = "code"> string encrypted with base64 algorithm </param>
/// <Returns> decrypted string </returns>
Public String decodebase64 (string code_type, string code)
{
String decode = "";
Byte [] bytes = convert. frombase64string (CODE); // encodes binary into an array of 8 unsigned integers.
Try
{
Decode = encoding. getencoding (code_type). getstring (bytes); // decodes a sequence of bytes from the specified byte array into a string.
}
Catch
{
Decode = code;
}
Return decode;
}
Turn: http://www.wewill.cn/n21194c66.aspx