{"id":14984088,"url":"https://github.com/globaltradingtechnologies/crypt-bundle","last_synced_at":"2025-04-10T19:43:30.172Z","repository":{"id":62513127,"uuid":"48439958","full_name":"GlobalTradingTechnologies/crypt-bundle","owner":"GlobalTradingTechnologies","description":"Provides symfony encryptor/decryptor services based on various cryptographic components","archived":false,"fork":false,"pushed_at":"2020-03-09T04:23:16.000Z","size":80,"stargazers_count":6,"open_issues_count":3,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T17:21:26.852Z","etag":null,"topics":["aes","bundle","decryptor","encryption","encryptor","rsa","security","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GlobalTradingTechnologies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-22T15:40:06.000Z","updated_at":"2020-03-09T04:23:19.000Z","dependencies_parsed_at":"2022-11-02T13:15:37.394Z","dependency_job_id":null,"html_url":"https://github.com/GlobalTradingTechnologies/crypt-bundle","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalTradingTechnologies%2Fcrypt-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalTradingTechnologies%2Fcrypt-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalTradingTechnologies%2Fcrypt-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalTradingTechnologies%2Fcrypt-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GlobalTradingTechnologies","download_url":"https://codeload.github.com/GlobalTradingTechnologies/crypt-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281424,"owners_count":21077423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","bundle","decryptor","encryption","encryptor","rsa","security","symfony-bundle"],"created_at":"2024-09-24T14:08:25.583Z","updated_at":"2025-04-10T19:43:30.145Z","avatar_url":"https://github.com/GlobalTradingTechnologies.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"CryptBundle\n===========\n\n[![Build Status](https://travis-ci.org/GlobalTradingTechnologies/crypt-bundle.svg?branch=master)](https://travis-ci.org/GlobalTradingTechnologies/crypt-bundle)\n[![Latest Stable Version](https://poser.pugx.org/gtt/crypt-bundle/version)](https://packagist.org/packages/gtt/crypt-bundle)\n[![Latest Unstable Version](https://poser.pugx.org/gtt/crypt-bundle/v/unstable)](//packagist.org/packages/gtt/crypt-bundle)\n[![License](https://poser.pugx.org/gtt/crypt-bundle/license)](https://packagist.org/packages/gtt/crypt-bundle)\n\nProvides a simple way to configure Symfony services for data encryption and decryption based on well-known encryption algorithms.\nWith the help of this CryptBundle you can encrypt or decrypt your data as simple as operate with elementary [EncryptorInterface](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/EncryptorInterface.php) or [DecryptorInterface](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/DecryptorInterface.php):\n```php\nuse Gtt\\Bundle\\CryptBundle\\Encryption\\EncryptorInterface;\nuse Gtt\\Bundle\\CryptBundle\\Encryption\\DecryptorInterface;\n\nclass MyMagicService\n{    \n    /**\n     * Encryptor\n     *\n     * @var EncryptorInterface\n     */\n    protected $encryptor;\n \n    /**\n     * Decryptor\n     *\n     * @var DecryptorInterface\n     */\n    protected $decryptor;\n    \n    public function __construct(EncryptorInterface $encryptor, DecryptorInterface $decryptor)\n    {\n        $this-\u003eencryptor = $encryptor;\n        $this-\u003edecryptor = $decryptor;\n    }\n    \n    public function doSomeMagic()\n    {\n        $someStringData = \"Crypt me!\";\n        $encrypted = $this-\u003eencryptor-\u003eencrypt($someStringData);\n        $decrypted = $this-\u003edecryptor-\u003edecrypt($encrypted);\n        \n        return $someStringData == $decrypted;\n    }\n}\n```\nImplementations of [EncryptorInterface](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/EncryptorInterface.php) or [DecryptorInterface](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/DecryptorInterface.php) would be provided by CryptBundle. The choice of encryption algorithm is up to you - you can specify it in bundle config.\n\nRequirements\n============\n\nRequires only PHP 5.6+ and symfony/framework-bundle.\n\nInstallation\n============\n\nBundle should be installed via composer\n\n```\ncomposer require gtt/crypt-bundle\n```\nAfter that you need to register the bundle inside your application kernel.\n\nAlso you probably need to install specific crypto libraries such as\n\n```\ncomposer install zendframework/zend-crypt\ncomposer install defuse/php-encryption\n```\n(You can add the libraries that you need. All of them are optional)\n\nEncryption\n==========\nUnder the hood bundle provides bridges to well-known php components for encrypting data as implementations of\n[encryptor](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/EncryptorInterface.php) and [decryptor](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/DecryptorInterface.php) interfaces.\nThis implementations are registered as a Symfony services that can be used by your code. See [Usage section](#Usage) for details.\n\n\nConfiguration\n=============\nBundle configuration defines one or several cryptor-sections grouped by encryption-type (for now supported types are aes and rsa) and the name of the pair of encryptor and decryptor (_aes_binary_cryptor_, _aes_log_cryptor_ and _rsa_default_cryptor_ in example below).\nEach cryptor-section contains options for defining the pair of encryptor and decryptor of certain encryption type.\nTou can turn on automatic encryption for database strings when using [doctrine/dbal](https://github.com/doctrine/dbal).\nYou can see example that holds configs for 2 pairs of aes encryptor and decryptor and one pair of rsa encryptor and decryptor\nand uses *rsa_default_cryptor* for encrypting database values:\n```yml\ngtt_crypt:\n    cryptors:\n        aes:\n            aes_binary_cryptor:\n                key_size: 128\n                key_path: \"/tmp/keys/aes/first.key\"\n                binary_output: true\n            aes_log_cryptor:\n                key_size: 128\n                key_path: \"/tmp/keys/aes/second.key\"\n                binary_output: false\n        rsa:\n            rsa_default_cryptor:\n                private_key: \"/tmp/keys/rsa/priv.key\"\n                public_key: \"/tmp/keys/rsa/pub.key\"\n                binary_output: false\n                padding: 4\n    doctrine:\n        dbal:\n            encrypted_string: rsa_default_cryptor\n```\nYou can see reference of configuration options for supported encryption types:\n### RSA\n- private_key - path to RSA private key\n- pass_phrase - RSA private key passphrase\n- public_key - path to RSA public key\n- binary_output - should be result of encryption encoded with base64 algorithm or should be input string base64-decoded before decryption\n- padding - number of distinct practices which all include adding data to the message prior to encryption.\n Should be one of constants from list below:\n-- OPENSSL_PKCS1_PADDING\n-- OPENSSL_SSLV23_PADDING\n-- OPENSSL_NO_PADDING\n-- OPENSSL_PKCS1_OAEP_PADDING\n\n### AES\n- key_size - AES key size. Should be 128 for 1.x or 256 for 2.x version of [defuse/php-encryption](https://github.com/defuse/php-encryption/)\n- key_path - path to AES private key. Can be generated by built in [crypt:aes:generate-key](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Command/GenerateKeyCommand.php) command\n- binary_output - should be result of encryption encoded with base64 algorithm or should be input string base64-decoded before decryption\n\nUsage\n=====\nIn order to use encryptos and decryptors in your code you have 3 availabilities:\n### Tag your service (recommended)\nThe prefered way to receive encryptor or decryptor in you service is to implement in the service's class very simple [EncryptorAwareInterface](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/EncryptorAwareInterface.php) or [DecryptorAwareInterface](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/DecryptorAwareInterface.php).\nYou can also use traits in most cases if you are too lazy: [SingleDecryptorAwareTrait](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/SingleDecryptorAwareTrait.php) and [SingleEncryptorAwareTrait](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/Encryption/SingleEncryptorAwareTrait.php).\nAfter that you should tag the service with `gtt.crypt.encryptor.aware` or `gtt.crypt.decryptor.aware` tag (depends on whether you want to get encryptor or decryptor) and specify cryptor name in tag attribute `cryptor_name`.\nFor example if you use configuration such as in [Configuration section](#Configuration) the _cryptor_name_ attribute value can be one of _aes_binary_cryptor_, _aes_log_cryptor_ or _rsa_default_cryptor_.\nThe setter injection (setters are defined in EncryptorAwareInterface/DecryptorAwareInterface interfaces) would be done by [CryptorInjectorPass](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/DependencyInjection/Compiler/CryptorInjectorPass.php).\n\n```yml\nservices:\n    gtt_encryptor_holder:\n        class: Your\\Class\\That\\Wants\\To\\Receive\\Encryptor\n        tags:\n            - { name: gtt.crypt.encryptor.aware, cryptor_name: \"aes_binary_cryptor\" }\n    gtt_decryptor_holder:\n        class: Your\\Class\\That\\Wants\\To\\Receive\\Decryptor\n        tags:\n            - { name: gtt.crypt.decryptor.aware, cryptor_name: \"aes_binary_cryptor\" }\n```\n\n### Inject cryptors directly by service id\nEach encryptor or decryptor configured by CryptBundle is a service with id constructed in accordance with the following pattern:\n`gtt.crypt.encryptor.\u003cname\u003e` for encryptors and `gtt.crypt.decryptor.\u003cname\u003e`, where \u003cname\u003e holds corresponding cryptor name defined in bundle config.\nFor example if you use configuration such as in [Configuration section](#Configuration) the \u003cname\u003e value can be one of _aes_binary_cryptor_, _aes_log_cryptor_ or _rsa_default_cryptor_.\nYou can simply inject these services in DI-configs of your bundles.\n\n### Use cryptor registry\nCrypt-bundle also registers [CryptorRegistry](https://github.com/GlobalTradingTechnologies/crypt-bundle/blob/master/CryptorRegistry.php) service with id _gtt.crypt.registry_ that collects all the encryptors and decryptors configured.\nYou can use it to get cryptors by calling getEncryptor or getDecryptor methods with name of the encryptor or decryptor specified.\nFor example if you use configuration such as in [Configuration section](#Configuration) the name can be one of _aes_binary_cryptor_, _aes_log_cryptor_ or _rsa_default_cryptor_.\n\n### Encrypting database values\nWhen database value encryption is enabled the `encrypted_string` dbal type is automatically registered. You can use this\ntype inside doctrine entities or direct dbal queries.\n```php\nuse Gtt\\Bundle\\CryptBundle\\Bridge\\Doctrine\\DBAL\\Enum\\TypeEnum;\n\n$this-\u003econnection-\u003eexecuteQuery(\n    'INSERT INTO something VALUES(:my_secret)',\n    ['my_secret' =\u003e 'A very secret value'],\n    ['my_secret' =\u003e TypeEnum::ENCRYPTED_STRING]\n)\n```\n\nSupported encryption components\n===============================\n* RSA (Based on [zendframework/zend-crypt](https://github.com/zendframework/zend-crypt))\n* AES (Based on [defuse/php-encryption](https://github.com/defuse/php-encryption/))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobaltradingtechnologies%2Fcrypt-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglobaltradingtechnologies%2Fcrypt-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobaltradingtechnologies%2Fcrypt-bundle/lists"}