需要引入命名空間:
1
2
|
using System; using System.Text; |
解碼:
1
2
3
4
5
6
7
8
9
|
public static string UnBase64String( string value) { if (value == null || value == "" ) { return "" ; } byte [] bytes = Convert.FromBase64String(value); return Encoding.UTF8.GetString(bytes); } |
編碼:
1
2
3
4
5
6
7
8
9
|
public static string ToBase64String( string value) { if (value == null || value == "" ) { return "" ; } byte [] bytes = Encoding.UTF8.GetBytes(value); return Convert.ToBase64String(bytes); } |
測試:
1
2
3
4
5
6
|
public static void Base64Test(){ string base64string = GameCommon.ToBase64String( "aaaa11233Base64編碼和解碼" ); string unbase64string = GameCommon.UnBase64String(base64string); Debug.Log( "base64string : " + base64string); Debug.Log( "unbase64string : " + unbase64string); } |
結(jié)果:
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對服務(wù)器之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
原文鏈接:https://blog.csdn.net/zgjllf1011/article/details/79220424