grafana/k6 · error
public exponent is even
Error message
public exponent is even
What it means
Thrown by crypto.subtle.generateKey for RSA algorithms (RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP) when publicExponent is even. validatePublicExponent (internal/js/modules/k6/webcrypto/rsa.go:147) mirrors Go's rsa package plus an explicit evenness check: phi(n) is always even for a two-prime modulus, so an even exponent can never be coprime with it and is rejected up front.
Solutions
- Use the standard exponent 65537, encoded as new Uint8Array([0x01, 0x00, 0x01])
- If policy forces a non-default exponent, choose an odd value between 3 and 2^31-1 (e.g. 3 or 17)
- If the exponent comes from config, assert it is odd before calling generateKey so the failure names the bad value
Example fix
// before publicExponent: new Uint8Array([0x01, 0x00, 0x00]) // 65536 — even // after publicExponent: new Uint8Array([0x01, 0x00, 0x01]) // 65537
Defensive patterns
Strategy: validation
Validate before calling
function decodeBigEndian(bytes) {
return bytes.reduce((acc, b) => acc * 256 + b, 0);
}
function validatePublicExponent(bytes) {
const e = decodeBigEndian(bytes);
if (e % 2 === 0) throw new Error(`publicExponent ${e} is even — use [0x01, 0x00, 0x01] (65537)`);
if (e < 2) throw new Error(`publicExponent ${e} is too small`);
if (e > 2 ** 31 - 1) throw new Error(`publicExponent ${e} is too large`);
return bytes;
}
validatePublicExponent(publicExponent);
await crypto.subtle.generateKey({ name: 'RSA-OAEP', modulusLength: 2048, publicExponent, hash: 'SHA-256' }, true, ['encrypt', 'decrypt']); Try / catch
try {
keyPair = await crypto.subtle.generateKey(alg, true, usages);
} catch (err) {
if (/public exponent/.test(String(err))) {
throw new Error(`bad publicExponent — falling back to 65537: ${err.message}`);
}
throw err;
} Prevention
- Standardize on 65537 ([0x01, 0x00, 0x01]) across all scripts
- Decode configured exponent bytes and assert odd, 2 <= e <= 2^31-1 before generateKey
- Watch for the 65536-vs-65537 off-by-one when typing hex bytes
When it happens
Trigger: Passing publicExponent: new Uint8Array([2]) (or any even big-endian byte sequence such as [0x01, 0x00, 0x00] = 65536) in the generateKey algorithm identifier. The error is thrown synchronously before any key generation work starts.
Common situations: Typing 65536 (0x10000) instead of the standard 65537 (0x01 0x00 0x01); a byte-shifted exponent array; an exponent read from configuration that was computed with a power of two.
Related errors
- public exponent too large
- public exponent too small
- exponent (e) is required
- modulus (n) is required
- coordinate Y is required
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/297540d0c74d8def.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/rsa.go:147
}
var err error
privateKey.handle, publicKey.handle, err = generateRSAKeyPair(rsakgp.ModulusLength, publicExponent)
if err != nil {
return nil, err
}
return &CryptoKeyPair{
PrivateKey: privateKey,
PublicKey: publicKey,
}, nil
}
// validatePublicExponent validates the public exponent.
// it's done same way how golang's rsa package does it + additional check for evenness.
func validatePublicExponent(e int) error {
if e%2 == 0 {
return errors.New("public exponent is even")
}
if e < 2 {
return errors.New("public exponent too small")
}
if e > 1<<31-1 {
return errors.New("public exponent too large")
}
return nil
}
func generateRSAKeyPair(
modulusLength int,
publicExponent int,
) (any, any, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, modulusLength)
if err != nil {View on GitHub (pinned to 01ffac6f24)