| ■No85617 (Azulean さん) に返信 > BASE64 を使うのも選択肢になるかもしれません。(= が大丈夫かは不安ですが)
BASE64 の = が現われるのはパディング部だけなので、 パディングが不要な実装、たとえば base64url が向いているかもしれません。 https://ja.wikipedia.org/wiki/Base64
// 保存したいバイナリ byte[] inBinary = { 0x96, 0xe9, 0x8d, 0xb3, 0x8a, 0xdb };
// ini ファイルで保存可能な base64url 文字列に変換 string iniString = inBinary.ToIniString();
// 元のバイナリに復元 byte[] outBinary = iniString.ToIniBinary();
static class Base64Extensions { public static string ToIniString(this byte[] bin) { return Convert.ToBase64String(bin).TrimEnd('=') .Replace('/', '_').Replace('+', '-'); } public static byte[] ToIniBinary(this string str) { int p = 4 - (str.Length % 4); string s = str; if (p != 4) { s += new string('=', p); } s = s.Replace('_', '/').Replace('-', '+'); return Convert.FromBase64String(s); } }
ini ファイルなら、+ → _ や / → - の置き換えは無くても大丈夫かも。 |