LoginSignup
3
1

More than 5 years have passed since last update.

バイナリファイルをBase64文字列に手っ取り早く変換するコード

Last updated at Posted at 2017-02-22

Stack Overflow探してみてもWhileを使うようなめんどくせーお行儀のいいコードばかり。
私みたいな不良C#erはお行儀よくできないので、以下の通りにしちゃいました。

var file = File.Open(@"D:\hoge\fuga.pfx", FileMode.Open);
var bytes = new BinaryReader(file).ReadBytes((int)file.Length);
Console.Write(Convert.ToBase64String(bytes));

※業務処理で使う場合はちゃんとUsing使ってくださいね!

2017/02/26 追記
コメント欄でもっと手っ取り早い方法をご教授いただきました。

var bytes = File.ReadAllBytes(@"D:\hoge\fuga.pfx");
Console.Write(Convert.ToBase64String(bytes));

ありがとうございます!

3
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1