最新の更新情報

2012年2月
« 1月    
 1234
567891011
12131415161718
19202122232425
26272829  

本ブログのURL

qrcode.png

雨雲の動き

お天気

 
 
吟遊詩人の戯言 内専用の記事検索...
 
 

【C#】文字列→Base64エンコード→文字列


キーワード(クリックで関連記事が読めます) → ,

関連記事



 
 

仕事で,文字列をBase64文字列へエンコード,
さらにBase64文字列から元の文字列へデコード

する必要があったので...

サンプルソースを書いておきます

文字列はUTF8を前提にしておりますです...

C#:
  1. ///--------------------------------------------------------------------
  2. //文字列をBASE64コードへ変換
  3. ///
  4. ///--------------------------------------------------------------------
  5. private string StringtoBase64(string st)
  6. {
  7.   byte [] bytesD;
  8.   bytesD = System.Text.Encoding.UTF8.GetBytes(st);
  9.  
  10.   string result;
  11.   result = System.Convert.ToBase64String(bytesD);
  12.  
  13.   return result;
  14. }
  15.  
  16. ///--------------------------------------------------------------------
  17. //BASE64コードを文字列へ変換
  18. ///
  19. ///--------------------------------------------------------------------
  20. private string Base64toString(string st)
  21. {
  22.   byte [] bs = System.Convert.FromBase64String(st);
  23.  
  24.   string result  = System.Text.Encoding.UTF8.GetString(bs);
  25.  
  26.   return result;
  27. }

 
 
 
 

コメントを残す

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">