C#BASE64 Encoding decoding __ Code

Source: Internet
Author: User
Tags base64
Using System;
Using System.Collections.Generic;
Using System.Linq;

Using System.Text;  Namespace Cat8637callcenter {public class CBase64 {///<summary>///encrypts the string using the Base64 algorithm/// </summary>///<param name= "Code_type" > Encoding type (encoded name)///* code page name///* 1200 "utf-16l" E "," utf-16 "," ucs-2 "," Unicode "or" iso-10646-ucs-2 "///* 1201///<summary>///use BAS for strings 
        E64 algorithm encryption///</summary>///<param name= "Code_type" > Encoding type (encoded 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-unicod" E-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 "> Strings to be encrypted </param& 
        Gt
        <returns> Encrypted string </returns> public static string EncodeBase64 (string code_type, String code)
            {String encode = ""; byte[] bytes = encoding.getencoding (code_type). GetBytes (code); 
            Encodes a set of characters into a sequence of bytes. 
            try {encode = convert.tobase64string (bytes);//Convert a subset of a 8-bit unsigned integer array to its equivalent, 64-based, numeric-encoded string form.
            catch {encode = code;
        return encode;
            public static string EncodeBase64 (string code) {String encode = ""; byte[] bytes = Encoding.Default.GetBytes (code); 
            Encodes a set of characters into a sequence of bytes. try {encode = Convert.tobase64String (bytes); 
            Converts a subset of a 8-bit unsigned integer array to its equivalent, 64-based, numeric-encoded string form.
            catch {encode = code;
        return encode; 
        }///<summary>///2013-11-05 New///decrypts a string using the Base64 algorithm///</summary> <param name= "Code_type" > Encoding type </param>///<param name= "code" > Strings that have been encrypted with the Base64 algorithm </param& 
        Gt
        <returns> decrypted string </returns> public static string DecodeBase64 (string code_type, String code)
            {String decode = ""; byte[] bytes = convert.frombase64string (code); 
            Converts the 2 feed encoding to an array of 8-bit 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;
  public static string DecodeBase64 (String code)      {String decode = ""; byte[] bytes = convert.frombase64string (code); 
            Converts the 2 feed encoding to an array of 8-bit unsigned integers. 
            try {decode = Encoding.Default.GetString (bytes);//decodes a sequence of bytes from the specified byte array into a string.
            catch {decode = code;
        return decode;
 }
    }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.