{"record":{"id":"157ede1ebef5e96a","repo":"phalcon/cphalcon","slug":"a-dependency-which-implements-cryptinterface-is-re","errorCode":null,"errorMessage":"A dependency which implements CryptInterface is required to use encryption","messagePattern":"A dependency which implements CryptInterface is required to use encryption","errorType":"exception","errorClass":"Phalcon\\Http\\Cookie\\Exceptions\\CryptInterfaceRequired","httpStatus":null,"severity":"error","filePath":"phalcon/Http/Cookie.zep","lineNumber":214,"sourceCode":"        let container = null,\n            name = this->name;\n\n        if this->isRead === false {\n            if !fetch value, _COOKIE[name] {\n                return defaultValue;\n            }\n\n            if this->useEncryption {\n                let container = <DiInterface> this->container;\n\n                if container === null {\n                    throw new CryptServiceUnavailable();\n                }\n\n                let crypt = <CryptInterface> container->getShared(\"crypt\");\n\n                if unlikely typeof crypt != \"object\" {\n                    throw new CryptInterfaceRequired();\n                }\n\n                /**\n                 * Verify the cookie's value if the sign key was set\n                 */\n                let signKey = this->signKey;\n\n                if typeof signKey === \"string\" {\n                    /**\n                     * Decrypt the value also decoding it with base64\n                     */\n                    let decryptedValue = crypt->decryptBase64(\n                        value,\n                        signKey\n                    );\n                } else {\n                    /**\n                     * Decrypt the value also decoding it with base64","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Http/Cookie.zep#L196-L232","documentation":"After resolving container->getShared('crypt'), Http\\Cookie verifies the returned service is an object before casting it to CryptInterface. A 'crypt' service defined as a non-object — a string (for example the key name), an array, or a definition that returns a scalar — throws CryptInterfaceRequired.","triggerScenarios":"The container defines 'crypt' as a plain string (a config value or key name) instead of a Crypt instance; a factory closure returns a scalar; the service resolves to null because the definition was unset or misnamed.","commonSituations":"Config-driven DI setups where 'crypt' is accidentally bound to the encryption key rather than the service; custom containers whose getShared() returns the raw definition instead of resolving it; copying config between projects with different service definitions.","solutions":["Register a real service: $di->setShared('crypt', fn() => new \\Phalcon\\Crypt\\Crypt())","Verify resolution: assert($di->getShared('crypt') instanceof \\Phalcon\\Encryption\\Crypt\\CryptInterface)","Fix custom container definitions so getShared('crypt') returns a resolved object"],"exampleFix":"// before\n$di->set('crypt', function () {\n    return $this->getConfig()->path('security.cryptKey'); // returns a string\n});\n\n// after\n$di->setShared('crypt', function () {\n    $crypt = new \\Phalcon\\Encryption\\Crypt\\Crypt();\n    $crypt->setKey($this->getConfig()->path('security.cryptKey'));\n\n    return $crypt;\n});","handlingStrategy":"validation","validationCode":"$crypt = Di::getDefault()?->getShared('crypt');\n\nif (!is_object($crypt) || !($crypt instanceof \\Phalcon\\Encryption\\Crypt\\CryptInterface)) {\n    throw new \\RuntimeException(\n        \"The 'crypt' service must resolve to an object implementing CryptInterface\"\n    );\n}\n\n$value = $cookie->getValue();","typeGuard":"/** @param mixed $service */\nfunction isCryptService($service): bool\n{\n    return is_object($service)\n        && $service instanceof \\Phalcon\\Encryption\\Crypt\\CryptInterface;\n}","tryCatchPattern":"try {\n    $value = $cookie->getValue();\n} catch (\\Phalcon\\Http\\Cookie\\Exceptions\\CryptInterfaceRequired $e) {\n    // the DI definition is wrong; surface it loudly rather than disabling encryption\n    $logger->critical($e->getMessage());\n    throw $e;\n}","preventionTips":["Register crypt as a setShared service returning a Crypt instance, never a key string","Add a container smoke test asserting getShared('crypt') instanceof CryptInterface","Never disable encryption to work around this error — fix the service definition"],"tags":["phalcon","http","cookie","crypt","dependency-injection","type-mismatch"],"backgroundTag":"service-type-mismatch","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}