c# 和 python 中解码的不同值

different value for decode in c# and python

我想在 Python 中获得相同的值 (PasswordHash),就像我在 C# 中以字节为单位获得它一样

C# 代码:

byte [] bytes = Convert.FromBase64String("AQAAAAEAACcQAAAAEAco3n3jFZc+9/IXf5IFpCnLz7Yx/c8lAw+cZ3JvFcWA8xL1Oa90gX/yzB6h6KsUgg==");
Text = BitConverter.ToString(bytes).Replace("-", string.Empty);
//output is 010000000100002710000000100728DE7DE315973EF7F2177F9205A429CBCFB631FDCF25030F9C67726F15C580F312F539AF74817FF2CC1EA1E8AB1482

Python代码:

x="AQAAAAEAACcQAAAAEAco3n3jFZc+9/IXf5IFpCnLz7Yx/c8lAw+cZ3JvFcWA8xL1Oa90gX/yzB6h6KsUgg=="
x_bytes = base64.b64decode(x)
y=str(x_bytes)[2:]
print(y.replace('\x',''))
#output is 01000000010000'100000001007(de}e31597>f7f2177f9205a4)cbcfb61fdcf%030f9cgro15c580f312f59aft817ff2cc1ea1e8ab1482"

你能解释一下区别吗?

它们都产生相同的字节序列:

01 00 00 00 01 00 00 27 10 00 00 00 10 07 28 DE
7D E3 15 97 3E F7 F2 17 7F 92 05 A4 29 CB CF B6
31 FD CF 25 03 0F 9C 67 72 6F 15 C5 80 F3 12 F5
39 AF 74 81 7F F2 CC 1E A1 E8 AB 14 82

你只是在解码后区别对待它们。

看起来你想要字节的十六进制。你只需要

bytes.hex()
>>> import base64
>>> b64 = "AQAAAAEAACcQAAAAEAco3n3jFZc+9/IXf5IFpCnLz7Yx/c8lAw+cZ3JvFcWA8xL1Oa90gX/yzB6h6KsUgg=="
>>> bytes = base64.b64decode(b64)
>>> bytes.hex()
'010000000100002710000000100728de7de315973ef7f2177f9205a429cbcfb631fdcf25030f9c67726f15c580f312f539af74817ff2cc1ea1e8ab1482'