如何使用 Groovy 生成十六进制摘要?

How to generate a hexdigest with Groovy?

我需要使用 AWS 4 签署请求,但签名密钥有问题。

来自 Amazon Doc

Use the digest (binary format) for the key derivation. Most languages have functions to compute either a binary format hash, commonly called a digest, or a hex-encoded hash, called a hexdigest. The key derivation requires that you use a binary-formatted digest.

所以我能够获得 byte[] 格式的签名密钥,但我无法将该值格式化为 hexdigest。

这是您要找的东西吗? .encodeHex()

byte[] printable = 'Rao'.bytes
println printable
// -> [82, 97, 111]
def printableHex = printable.encodeHex()
println printableHex.toString()
// -> 52616f