grafana/k6 · error

unsupported algorithm

Error message

unsupported algorithm: %v

What it means

Returned by extractAlg when the object held in the CryptoKey's Algorithm field implements neither the hasHash interface (HMAC-style, exposing a hash name) nor the hasAlg interface (AES-style, exposing an algorithm name). I.e. the key's algorithm is of an unrecognized Go type, so no JWK `alg` string (HS*/A*) can be derived for export. Fires during symmetric key JWK export.

Solutions

  1. Create keys with supported algorithms: HMAC, AES-GCM, AES-CBC, AES-CTR, or AES-KW
  2. Use raw or AESJWK import formats that construct a proper algorithm object instead of hand-crafted ones
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

}

func extractAlg(inAlg any, keyLen int) (string, error) {
	switch alg := inAlg.(type) {
	case hasHash:
		v := alg.hash()
		if len(v) < 4 {
			return "", errors.New("length of hash algorithm is less than 4: " + v)
		}
		return "HS" + v[4:], nil
	case hasAlg:
		v := alg.alg()
		if len(v) < 4 {
			return "", errors.New("length of named algorithm is less than 4: " + v)
		}

		return fmt.Sprintf("A%d%s", (8 * keyLen), v[4:]), nil
	default:
		return "", fmt.Errorf("unsupported algorithm: %v", inAlg)
	}
}

// ecJWK represents an EC JWK key.
// It is used to unmarshal ECDSA and ECDH keys to and from JWK format.
type ecJWK struct {
	// Key type
	Kty string `json:"kty"`
	// Canonical Curve
	Crv string `json:"crv"`
	// X coordinate
	X string `json:"x"`
	// Y coordinate
	Y string `json:"y"`
	// Private scalar
	D string `json:"d"`
}

View on GitHub (pinned to 8d06114777)