如何验证长度为128的ED25519签名



Go的crypto/ed25519包出现问题。我正在尝试验证消息的签名,但我必须验证的签名和公钥比crypto/ed25519支持的要长。

crypto/ed25519包中,支持的密钥和签名的长度有限制:

const (
// PublicKeySize is the size, in bytes, of public keys as used in this package.
PublicKeySize = 32
// PrivateKeySize is the size, in bytes, of private keys as used in this package.
PrivateKeySize = 64
// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
SignatureSize = 64
// SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032.
SeedSize = 32
)

但我必须使用的密钥来验证消息比这更长:

SignatureSize = 128
PublicKeySize = 64

当我尝试使用Verify(...)函数时,由于签名和公钥的大小,它会返回false。我该怎么做才能以当前长度验证我的签名?

您拥有的密钥和签名很可能是十六进制编码的,以保持它们的可读性,并易于在标头、json等中传输。

先尝试解码:

const s = "48656c6c6f20476f7068657221"
decoded, err := hex.DecodeString(s)
if err != nil {
log.Fatal(err)
}
fmt.Println(len(decoded))

最新更新