Pro*_*mer 7 java kotlin ed25519 java-15
由于 Ed25519 出现的时间不长(在 JDK 中),因此关于如何使用它的资源很少。
虽然他们的示例非常简洁和有用,但我在理解密钥解析方面做错了什么时遇到了一些困难。
他们的公钥是从 iDevice 发送的数据包中读取的。
(这么说吧,它是一个字节数组)
通过搜索并尽力了解密钥的编码方式,我偶然发现了这条消息。
4. The public key A is the encoding of the point [s]B. First,
encode the y-coordinate (in the range 0 <= y < p) as a little-
endian string of 32 octets. The most significant bit of the
final octet is always zero. To form the encoding of the point
[s]B, copy the least significant bit of the x coordinate to the
most significant bit of the final octet. The result is the
public key.
Run Code Online (Sandbox Code Playgroud)
这意味着如果我想得到y,isXOdd我就必须做一些工作。
(如果我理解正确的话)
下面是它的代码,但验证仍然失败。
我认为,我通过反转数组将其返回到 Big Endian 供 BigInteger 使用来正确完成此操作。
我的问题是:
4. The public key A is the encoding of the point [s]B. First,
encode the y-coordinate (in the range 0 <= y < p) as a little-
endian string of 32 octets. The most significant bit of the
final octet is always zero. To form the encoding of the point
[s]B, copy the least significant bit of the x coordinate to the
most significant bit of the final octet. The result is the
public key.
Run Code Online (Sandbox Code Playgroud)
和数据(操作前)(全部为十六进制):
Device identifier: 34444432393531392d463432322d343237442d414436302d444644393737354244443533
Device public key: e0a611c84db0ae91abfe2e6db91b6a457a4b41f9d8e09afdc7207ce3e4942e94
Device signature: a0383afb3bcbd43d08b04274a9214036f16195dc890c07a81aa06e964668955b29c5026d73d8ddefb12160529eeb66f843be4a925b804b575e6a259871259907
Device info: a86a71d42874b36e81a0acc65df0f2a84551b263b80b61d2f70929cd737176a434444432393531392d463432322d343237442d414436302d444644393737354244443533e0a611c84db0ae91abfe2e6db91b6a457a4b41f9d8e09afdc7207ce3e4942e94
// Device info is simply concatenated [hkdf, identifier, public key]
Run Code Online (Sandbox Code Playgroud)
以及操作后的公钥:
e0a611c84db0ae91abfe2e6db91b6a457a4b41f9d8e09afdc7207ce3e4942e14
Run Code Online (Sandbox Code Playgroud)
非常感谢,非常感谢您的每一点帮助。当 Ed25519 实现不再那么新鲜时,这将帮助更多稍后偶然发现这个问题的人。
事实上,整个编码和解码都是正确的。最后的一件事是,问题是我(错误地)反转了我读取了太多次的数组。
反转数组,因为某些键以小端编码,而为了在 JVM 中将其表示为 BigInteger,您必须反转小端,使其变为大端。
希望这对将来遇到类似问题的每个人都有帮助。
如果有任何疑问,只需在这里评论或给我留言。我会尽力帮助你。
| 归档时间: |
|
| 查看次数: |
2146 次 |
| 最近记录: |