ASP CORE: asp-for字节数组使用了哪种编码(不是base64吗?)以及如何解码?

ASP CORE: which encoding is used by asp-for for byte array (is it not base64?) and how to decode it?

我发现

<input hidden type="hidden" asp-for="@Model.Entity.RowVersion" />

for rowVersion = 0x000000000004FAE7 将值编码为 AAAAAAAE&#x2B;uc= 。 但是当我尝试用 Convert.FromBase64String 解码它时,我得到

System.FormatException: 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters,

https://base64.guru/converter/decode对识别算法没有帮助。

如果不使用 Convert.FromBase64String 如何解码?

P.S。 Microsoft.Extensions.WebEncoders 软件包没有帮助。

RowVersion 用于乐观并发。这是一个时间戳,因此它是数据库生成的,不应发布。删除输入。你不需要它也不应该出现在你的视野中。

这个字符串:

AAAAAAAE&#x2B;uc=

看起来 HTML 已编码,因为其中有 &#x2B;,这是一个已编码的 + 字符。

所以如果先按HTML规则解码,再按Base64规则解码,应该可以:

string input = "AAAAAAAE&#x2B;uc=";
string decoded = HttpUtility.HtmlDecode(input);
byte[] bytes = Convert.FromBase64String(decoded);
string output = string.Join("", bytes.Select(b => b.ToString("x2")));
Console.WriteLine(output);

输出:

000000000004fae7