{"record":{"id":"d717d27355560219","repo":"grafana/k6","slug":"key-s-handle-isn-t-an-rsa-public-private-key-got","errorCode":null,"errorMessage":"key's handle isn't an RSA public/private key, got: %T","messagePattern":"key's handle isn't an RSA public/private key, got: %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":424,"sourceCode":"\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()))\n\t\texported.Set(\"qi\", base64URLEncode(rsaKey.Precomputed.Qinv.Bytes()))\n\tcase *rsa.PublicKey:\n\t\texported.Set(\"n\", base64URLEncode(rsaKey.N.Bytes()))\n\t\texported.Set(\"e\", base64URLEncode(big.NewInt(int64(rsaKey.E)).Bytes()))\n\tcase rsa.PublicKey:\n\t\texported.Set(\"n\", base64URLEncode(rsaKey.N.Bytes()))\n\t\texported.Set(\"e\", base64URLEncode(big.NewInt(int64(rsaKey.E)).Bytes()))\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"key's handle isn't an RSA public/private key, got: %T\", key.handle)\n\t}\n\n\treturn exported, nil\n}\n","sourceCodeStart":406,"sourceCodeEnd":429,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/webcrypto/jwk.go#L406-L429","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/webcrypto/jwk.go:424 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}