grafana/k6 · error
key's handle isn't an RSA public/private key, got: %T
Error message
key's handle isn't an RSA public/private key, got: %T
What it means
Raised by exportRSAJWK when the CryptoKey being exported does not hold an *rsa.PrivateKey or *rsa.PublicKey in its internal handle — the type switch on key.handle fell through to the default branch, reporting the actual Go type. Means exportKey('jwk') was called on a key that is not RSA (e.g. an EC or HMAC key paired with an RSA export call path), or the key object was constructed inconsistently.
Source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:424
switch rsaKey := key.handle.(type) {
case *rsa.PrivateKey:
exported.Set("n", base64URLEncode(rsaKey.N.Bytes()))
exported.Set("e", base64URLEncode(big.NewInt(int64(rsaKey.E)).Bytes()))
exported.Set("d", base64URLEncode(rsaKey.D.Bytes()))
exported.Set("p", base64URLEncode(rsaKey.Primes[0].Bytes()))
exported.Set("q", base64URLEncode(rsaKey.Primes[1].Bytes()))
exported.Set("dp", base64URLEncode(rsaKey.Precomputed.Dp.Bytes()))
exported.Set("dq", base64URLEncode(rsaKey.Precomputed.Dq.Bytes()))
exported.Set("qi", base64URLEncode(rsaKey.Precomputed.Qinv.Bytes()))
case *rsa.PublicKey:
exported.Set("n", base64URLEncode(rsaKey.N.Bytes()))
exported.Set("e", base64URLEncode(big.NewInt(int64(rsaKey.E)).Bytes()))
case rsa.PublicKey:
exported.Set("n", base64URLEncode(rsaKey.N.Bytes()))
exported.Set("e", base64URLEncode(big.NewInt(int64(rsaKey.E)).Bytes()))
default:
return nil, fmt.Errorf("key's handle isn't an RSA public/private key, got: %T", key.handle)
}
return exported, nil
}
View on GitHub (pinned to 01ffac6f24)
Solutions
- Only export keys as RSA JWK when they were generated/imported with an RSA algorithm (RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP)
- Check the %T value in the message to see what key type you actually hold, and export with the matching format/algorithm
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:424 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/d717d27355560219.
Report an issue: GitHub.