grafana/k6 · error
failed to decode modulus
Error message
failed to decode modulus: %w
What it means
Returned by importRSAJWK when the JWK's `n` field (the RSA modulus) fails base64url decoding. Structure and required-field validation passed, but the modulus string contains characters outside the base64url alphabet or has an invalid length, so the key size and public key cannot be constructed.
Solutions
- Encode n as unpadded base64url of the big-endian modulus bytes (256/384/512 bytes for RSA-2048/3072/4096)
- Avoid plain base64 with '+' and '/' characters — convert to the URL-safe alphabet
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:337 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/ff338f3fab93f2cb.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:338
// TODO: consider validating the other fields in future
return nil
}
func importRSAJWK(jsonKeyData []byte) (any, CryptoKeyType, int, error) {
var jwk rsaJWK
if err := json.Unmarshal(jsonKeyData, &jwk); err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to parse input as RSA JWK key: %w", err)
}
if err := jwk.validate(); err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("invalid RSA JWK key: %w", err)
}
// decode the various key components
nBytes, err := base64URLDecode(jwk.N)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode modulus: %w", err)
}
eBytes, err := base64URLDecode(jwk.E)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode exponent: %w", err)
}
// convert exponent to an integer
eInt := new(big.Int).SetBytes(eBytes).Int64()
pubKey := rsa.PublicKey{
N: new(big.Int).SetBytes(nBytes),
E: int(eInt),
}
// if the private exponent is missing, return the public key
if jwk.D == "" {
return pubKey, PublicCryptoKeyType, pubKey.N.BitLen(), nil
}
View on GitHub (pinned to 8d06114777)