{"record":{"id":"69fcb3d9e4cbeb2b","repo":"grafana/k6","slug":"failed-to-validate-private-key-w","errorCode":null,"errorMessage":"failed to validate private key: %w","messagePattern":"failed to validate private key: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":398,"sourceCode":"\t}\n\n\tprivKey := &rsa.PrivateKey{\n\t\tPublicKey: pubKey,\n\t\tD:         new(big.Int).SetBytes(dBytes),\n\t\tPrimes: []*big.Int{\n\t\t\tnew(big.Int).SetBytes(pBytes),\n\t\t\tnew(big.Int).SetBytes(qBytes),\n\t\t},\n\t\tPrecomputed: rsa.PrecomputedValues{\n\t\t\tDp:   new(big.Int).SetBytes(dpBytes),\n\t\t\tDq:   new(big.Int).SetBytes(dqBytes),\n\t\t\tQinv: new(big.Int).SetBytes(qiBytes),\n\t\t},\n\t}\n\n\terr = privKey.Validate()\n\tif err != nil {\n\t\treturn nil, UnknownCryptoKeyType, 0, fmt.Errorf(\"failed to validate private key: %w\", err)\n\t}\n\n\treturn privKey, PrivateCryptoKeyType, pubKey.N.BitLen(), nil\n}\n\nfunc exportRSAJWK(key *CryptoKey) (any, error) {\n\texported := &JsonWebKey{}\n\texported.Set(\"kty\", \"RSA\")\n\n\tswitch rsaKey := key.handle.(type) {\n\tcase *rsa.PrivateKey:\n\t\texported.Set(\"n\", base64URLEncode(rsaKey.N.Bytes()))\n\t\texported.Set(\"e\", base64URLEncode(big.NewInt(int64(rsaKey.E)).Bytes()))\n\t\texported.Set(\"d\", base64URLEncode(rsaKey.D.Bytes()))\n\t\texported.Set(\"p\", base64URLEncode(rsaKey.Primes[0].Bytes()))\n\t\texported.Set(\"q\", base64URLEncode(rsaKey.Primes[1].Bytes()))\n\t\texported.Set(\"dp\", base64URLEncode(rsaKey.Precomputed.Dp.Bytes()))\n\t\texported.Set(\"dq\", base64URLEncode(rsaKey.Precomputed.Dq.Bytes()))","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/webcrypto/jwk.go#L380-L416","documentation":"Returned by importRSAJWK at the final stage: all JWK fields decoded successfully and an rsa.PrivateKey was assembled, but Go's privKey.Validate() rejected it — the mathematical relationship between primes, exponents and CRT coefficients does not hold (e.g. mismatched p/q from different keys, or corrupted integers). The wrapped error gives the exact consistency check that failed.","triggerScenarios":"Thrown at internal/js/modules/k6/webcrypto/jwk.go:397 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-export the JWK from the original key store — mixed components from different keys are the usual cause","Confirm p, q, dp, dq and qi all belong to the same modulus and exponent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}