gpt4 book ai didi

shell - openssl 生成的随机字符串不是那么随机。

转载 作者:行者123 更新时间:2023-12-04 18:43:04 29 4
gpt4 key购买 nike

当我使用 openssl rand 生成一个随机字符串时,为什么它的末尾总是有一个 = ?

如果我将位数减少到 16,我总是在最后得到两个等于 (==)。我想知道为什么会这样。男人

例如在运行 OS X 特立独行的 Macbook 中

$ Darwin aria.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
$ for i in $(seq 1 10)
for> do
for> openssl rand -base64 32
for> done

dDzk7B6SrcMnpkO2LLM4TaWKMjzBXHj1CmLO4t0HXdo=
QtP2kxQBg+yOCmowvEDWNdrSLobYyeXRz6HLDq3Q6rA=
iRmlr1JxRYjVGq3zkX9jgAoSAbu1F2Wm6CRJ9ZvYCR0=
Z/Wg//Z4Xjpzl3/ve87D2Pyk+dUgm6XHpFpyyeGXJKw=
XAVdp2B0RJlPCYRBBs3Q+C8X8aEbLQgXgXo5bhZkn8s=
eu8JcAwupYrX7GPfVnihTKXbzSsRYyW8VUWi+TN8oYA=
ZHPIj9PgiOi2SPwfrO4nKH1gIFEXlgXM320yDdpOelw=
7zjdIlSDT2lYiUziGx4Nc+uhoAlfTQKnXW+wB5omG6M=
nu+QKhD50dE6EQqCD56sPzMSARWuqi2d39UVtTyk0+w=
Wd4xQ/Eh1lnCiSn9cds4/mRc3FTEunhvrGskl3rJwZ4=

我在我拥有的 debian 盒子中重复了这一点,
$ uname -a
Linux ip-10-229-17-26 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
$ for i in $(seq 1 10)
> do
> openssl rand -base64 32
> done

pq+imMSMaXg2qW25d+/QCh3fVv/QevgdOXYZc4UlDRk=
lDm4Rno9jUikYOd0II225J97dExqLs4yl2gDSRDrafU=
QyYGkx1tgEWOiAmK4fTdbsnDPcfhjh3WejcBr1JdRlE=
P9RRi6JDo0/cWVXtReDJ6lA0XKiT9CB8bMePl7vMH2U=
z/TSy0qAfijl9mCKjxGsZfJySnbqGO3ML2/QYwsent8=
zLjDTakHyp6cJn16kKuTeQLY3azVuA/gTJ5XZshoahY=
uVxA/YweYs4HFxYa+3aJG3c5V0wFNmX+6VjZwjgbr8Q=
7Lx4W6t4GkfoZez3pspOVop2lL1KuTQgGn9KJtaWU44=
OF5DfOP4c/V+WmxvBpS5QRyGd2j+cqoDKUkwlTd1T0I=
2ANn1T07mmECnmzOgLDMjJvU/VrRVWbkCf6qgBQpg3A=

最佳答案

“=”和/或“==”来自base 64 padding。 “==”和/或“=”序列分别表示最后一组仅包含 8 位或 16 位。

看看这个 wikipedia post .

和从上面复制/粘贴:

When decoding Base64 text, four characters are typically converted back to three bytes. The only exceptions are when padding characters exist. A single '=' indicates that the four characters will decode to only two bytes, while '==' indicates that the four characters will decode to only a single byte.

关于shell - openssl 生成的随机字符串不是那么随机。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20513371/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com