grafana/k6 · error

failed to parse input as RSA JWK key

Error message

failed to parse input as RSA JWK key: %w

What it means

Returned by importRSAJWK when the data passed to crypto.subtle.importKey(format='jwk') with an RSA algorithm is not valid JSON — json.Unmarshal into the rsaJWK struct failed before any field validation. The wrapped error pinpoints the JSON syntax problem.

Solutions

  1. Pass a serialized RSA JWK object (JSON.stringify) with kty, n and e fields
  2. Check for truncated or double-encoded key strings
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:327 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/35dfb1c766da18ba. Report an issue: GitHub.

Appendix: source

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

		return fmt.Errorf("invalid key type: %s", jwk.Kty)
	}

	if jwk.N == "" {
		return errors.New("modulus (n) is required")
	}

	if jwk.E == "" {
		return errors.New("exponent (e) is required")
	}

	// 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()

View on GitHub (pinned to 8d06114777)