ゼロから昇順のベース64桁は、大文字の「A」〜「Z」、小文字の「a」〜「z」、 の数字「0」〜「9」、記号「+」および「/」を含む。無価値の 文字 "="は、末尾のパディングに使用されます。Convert.ToBase64String()はどのように機能しますか?
したがって、次のバイト配列はConvert.ToBase64String()
でどのように変換されますか?特に元のバイト配列は10要素を持ち、変換された文字列は16文字あるのはなぜですか?
using System;
public class Example
{
public static void Main()
{
// Define a byte array.
byte[] bytes = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
Console.WriteLine("The byte array: ");
Console.WriteLine(" {0}\n", BitConverter.ToString(bytes));
// Convert the array to a base 64 sring.
String s = Convert.ToBase64String(bytes);
Console.WriteLine("The base 64 string:\n {0}\n", s);
// Restore the byte array.
byte[] newBytes = Convert.FromBase64String(s);
Console.WriteLine("The restored byte array: ");
Console.WriteLine(" {0}\n", BitConverter.ToString(newBytes));
}
}
// The example displays the following output:
// The byte array:
// 02-04-06-08-0A-0C-0E-10-12-14
//
// The base 64 string:
// AgQGCAoMDhASFA==
//
// The restored byte array:
// 02-04-06-08-0A-0C-0E-10-12-14
あなたは[what base64 is](https://en.wikipedia.org/wiki/Base64)を読むことができます。これは、Base64エンコーディングタイプに関するこの質問やその他の質問に答える必要があります。 – Abion47
私は現在の状態でこの記事のために見ることができる唯一の答えは "Convert.ToBase64Stringは正しく動作します"です。あなたは、あなたが何を期待しているか、あなたが理解していないこと、そしてhttps://referencesource.microsoft.com/#mscorlib/system/convert.cs,37f71bcd2a713cd5のどの部分が不明であるかを明確にしてください。 –
Wikiの回答は@ Abion47と書いてありますが、非常に明確で精巧です。もっと具体的な質問があればお気軽にお問い合わせください。 –