{"record":{"id":"91cbfb0e7dd8eabb","repo":"ory/hydra","slug":"unknown-algorithm-s-for-signing-key","errorCode":null,"errorMessage":"unknown algorithm %s for signing key","messagePattern":"unknown algorithm (.+?) for signing key","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/josex/generate.go","lineNumber":82,"sourceCode":"\t\t}\n\t\treturn key.Public(), key, err\n\tcase jose.ES512:\n\t\tkey, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\treturn key.Public(), key, err\n\tcase jose.EdDSA:\n\t\tpub, key, err := ed25519.GenerateKey(rand.Reader)\n\t\treturn pub, key, err\n\tcase jose.RS256, jose.RS384, jose.RS512, jose.PS256, jose.PS384, jose.PS512:\n\t\tkey, err := rsa.GenerateKey(rand.Reader, bits)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\treturn key.Public(), key, err\n\tdefault:\n\t\treturn nil, nil, fmt.Errorf(\"unknown algorithm %s for signing key\", alg)\n\t}\n}\n\n// NewEncryptionKey generates a keypair for corresponding KeyAlgorithm.\nfunc NewEncryptionKey(alg jose.KeyAlgorithm, bits int) (crypto.PublicKey, crypto.PrivateKey, error) {\n\tswitch alg {\n\tcase jose.RSA1_5, jose.RSA_OAEP, jose.RSA_OAEP_256:\n\t\tif bits == 0 {\n\t\t\tbits = 2048\n\t\t}\n\t\tif bits < 2048 {\n\t\t\treturn nil, nil, errors.New(\"invalid key size for RSA key, 2048 or more is required\")\n\t\t}\n\t\tkey, err := rsa.GenerateKey(rand.Reader, bits)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\treturn key.Public(), key, err","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/josex/generate.go#L64-L100","documentation":"NewSigningKey generates a keypair only for the JOSE signature algorithms it knows: ES256/384/512, EdDSA, RS256/384/512, PS256/384/512. Passing any other jose.SignatureAlgorithm falls into the default branch and returns this error instead of a key.","triggerScenarios":"Calling josex.NewSigningKey with an algorithm such as HS256 (symmetric, unsupported here), a typo like \"ES512K\", or an encryption-only algorithm like RSA-OAEP-256; also via GenerateJWK or tests like assertCreateVerifiableCredential configured with such an alg.","commonSituations":"Config files where a signing alg was set to HMAC (HS*) which requires a shared secret, not a generated keypair; copying an encryption alg into the signing config; string algorithms that do not match go-jose constants.","solutions":["Use one of the supported algorithms: ES256, ES384, ES512, EdDSA, RS256, RS384, RS512, PS256, PS384, PS512","If you need HMAC (HS*), generate a []byte secret yourself instead of calling NewSigningKey","Validate the alg value from config against the supported list before calling NewSigningKey and fail with a clear config error"],"exampleFix":"// before\nkey, priv, err := josex.NewSigningKey(jose.SignatureAlgorithm(\"HS256\"), 0)\n// after\nkey, priv, err := josex.NewSigningKey(jose.ES256, 0)","handlingStrategy":"validation","validationCode":"var supportedSigningAlgs = map[jose.SignatureAlgorithm]bool{\n    jose.ES256: true, jose.ES384: true, jose.ES512: true, jose.EdDSA: true,\n    jose.RS256: true, jose.RS384: true, jose.RS512: true,\n    jose.PS256: true, jose.PS384: true, jose.PS512: true,\n}\nfunc checkSigningAlg(alg jose.SignatureAlgorithm) error {\n    if !supportedSigningAlgs[alg] {\n        return fmt.Errorf(\"alg %q not supported for key generation\", alg)\n    }\n    return nil\n}","typeGuard":"func isAsymmetricSigningAlg(alg string) bool {\n    switch alg {\n    case \"ES256\", \"ES384\", \"ES512\", \"EdDSA\", \"RS256\", \"RS384\", \"RS512\", \"PS256\", \"PS384\", \"PS512\":\n        return true\n    }\n    return false\n}","tryCatchPattern":"pub, priv, err := josex.NewSigningKey(alg, bits)\nif err != nil {\n    return fmt.Errorf(\"config error: cannot generate signing key: %w\", err)\n}","preventionTips":["Keep a whitelist of allowed algs in config parsing and validate at startup","Never configure HS* algorithms for keypair generation — use raw secrets for HMAC","Use go-jose constants (jose.ES256 etc.) instead of raw strings","Add a unit test that generates a key for every alg your product claims to support"],"tags":["jose","jwk","crypto","go"],"backgroundTag":"unsupported-jose-algorithm","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}