Implement BASE64 encryption and decryption

Source: Internet
Author: User

usingSystem;
usingSystem.Text;

namespaceCommon
{
/// <summary>
///implement BASE64 encryption and decryption
/// </summary>
PublicSealedclassBase64
{
/// <summary>
///BASE64 Encryption
/// </summary>
/// <param name= "codename" >encoding used for encryption</param>
/// <param name= "source" >plaintext to encrypt</param>
/// <returns></returns>
Public StaticstringEncodeBase64 (Encoding encode,stringSource
{
byte[] bytes = encode. GetBytes (source);
Try
{
encode = convert.tobase64string (bytes);
}
Catch
{
encode = source;
}
returnEncode
}

/// <summary>
///Base64 encryption, encrypted by UTF8 encoding
/// </summary>
/// <param name= "source" >plaintext to encrypt</param>
/// <returns>the encrypted string</returns>
PublicStaticstringEncodeBase64 (stringSource
{
returnEncodeBase64 (Encoding.UTF8, source);
}

/// <summary>
///Base64 Decryption
/// </summary>
/// <param name= "codename" >Decryption is encoded in a way that is consistent with the way encryption is used</param>
/// <param name= "Result" >ciphertext to be decrypted</param>
/// <returns>the decrypted string</returns>
PublicStaticstringDecodeBase64 (Encoding encode,stringResult
{
stringdecode ="";
byte[] bytes = convert.frombase64string (result);
Try
{
decode = encode. GetString (bytes);
}
Catch
{
decode = result;
}
returnDecode
}

/// <summary>
///Base64 decryption, using UTF8 encoding method to decrypt
/// </summary>
/// <param name= "Result" >ciphertext to be decrypted</param>
/// <returns>the decrypted string</returns>
PublicStaticstringDecodeBase64 (stringResult
{
returnDecodeBase64 (Encoding.UTF8, result);
}
}
}

Implement BASE64 encryption and decryption

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.