grafana/k6 · error
failed to decode first prime factor
Error message
failed to decode first prime factor: %w
What it means
Returned by importRSAJWK when the private JWK's `p` field (first prime factor) fails base64url decoding. Occurs only for private key imports where d decoded successfully; the malformed prime prevents reconstruction of the rsa.PrivateKey.
Solutions
- Encode p as unpadded base64url of the half-modulus-sized big-endian prime
- Export the JWK from the original key material rather than re-typing components
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:362 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/9235e1e263fab50d.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:363
// 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)
}
pBytes, err := base64URLDecode(jwk.P)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode first prime factor: %w", err)
}
qBytes, err := base64URLDecode(jwk.Q)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode second prime factor: %w", err)
}
dpBytes, err := base64URLDecode(jwk.Dp)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode first exponent: %w", err)
}
dqBytes, err := base64URLDecode(jwk.Dq)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode second exponent: %w", err)
}
qiBytes, err := base64URLDecode(jwk.Qi)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode coefficient: %w", err)
}
View on GitHub (pinned to 8d06114777)