grafana/k6 · error

invalid RSA JWK key

Error message

invalid RSA JWK key: %w

What it means

Returned by importRSAJWK when the input parsed as JSON but failed rsaJWK semantic validation: `kty` is not "RSA", the modulus `n` is missing/empty, or the exponent `e` is missing/empty. Other RSA fields (d, p, q, dp, dq, qi) are not validated at this stage — failures with those surface later as decode errors.

Solutions

  1. Ensure the JWK has "kty":"RSA" plus non-empty base64url-encoded "n" and "e"
  2. Copy a complete JWK from the generating tool rather than hand-building it
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

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

		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()
	pubKey := rsa.PublicKey{
		N: new(big.Int).SetBytes(nBytes),
		E: int(eInt),
	}

View on GitHub (pinned to 8d06114777)