How do I encode and decode a base64 string?

前端 未结 10 2272
我在风中等你
我在风中等你 2020-11-22 03:41
  1. How do I return a base64 encoded string given a string?

  2. How do I decode a base64 encoded string into a string?

10条回答
  •  一向
    一向 (楼主)
    2020-11-22 04:36

    One liner code:

    Note: Use System and System.Text directives.

    Encode:

    string encodedStr = Convert.ToBase64String(Encoding.UTF8.GetBytes("inputStr"));
    

    Decode:

    string inputStr = Encoding.UTF8.GetString(Convert.FromBase64String(encodedStr));
    

提交回复
热议问题