仕事で,文字列をBase64文字列へエンコード,
さらにBase64文字列から元の文字列へデコード
する必要があったので...
サンプルソースを書いておきます
文字列はUTF8を前提にしておりますです...
C#:
- ///--------------------------------------------------------------------
- //文字列をBASE64コードへ変換
- ///
- ///--------------------------------------------------------------------
- private string StringtoBase64(string st)
- {
- byte [] bytesD;
- bytesD = System.Text.Encoding.UTF8.GetBytes(st);
- string result;
- result = System.Convert.ToBase64String(bytesD);
- return result;
- }
- ///--------------------------------------------------------------------
- //BASE64コードを文字列へ変換
- ///
- ///--------------------------------------------------------------------
- private string Base64toString(string st)
- {
- byte [] bs = System.Convert.FromBase64String(st);
- string result = System.Text.Encoding.UTF8.GetString(bs);
- return result;
- }



