grafana/k6 · error

failed to decode exponent

Error message

failed to decode exponent: %w

What it means

Returned by importRSAJWK when the JWK's `e` field (the RSA public exponent) fails base64url decoding. The modulus decoded fine, but the exponent string (typically encoding 65537 as 'AQAB') is malformed, so the rsa.PublicKey cannot be assembled.

Solutions

  1. Use the standard encoding: 'AQAB' for the common exponent 65537
  2. Re-encode e as unpadded base64url of the big-endian exponent bytes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:341 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/7c915ad2dbf30ec9. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/webcrypto/jwk.go:342

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
	}

	dBytes, err := base64URLDecode(jwk.D)
	if err != nil {
		return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode private exponent: %w", err)
	}

View on GitHub (pinned to 8d06114777)