{"id":15412140,"url":"https://github.com/maymeow/php-encrypt","last_synced_at":"2025-04-19T11:33:56.749Z","repository":{"id":32397371,"uuid":"132498589","full_name":"MayMeow/php-encrypt","owner":"MayMeow","description":"🔏PHP library for creating and signing Certificates, text encryption and decryption.","archived":false,"fork":false,"pushed_at":"2023-01-06T18:27:18.000Z","size":1929,"stargazers_count":7,"open_issues_count":18,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-06T10:17:27.584Z","etag":null,"topics":["certificates","encryption","hacktoberfest","hacktoberfest2020","library","openssl","php","security"],"latest_commit_sha":null,"homepage":"https://wiki.0x0.sk/en/php-encrypt","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/MayMeow.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"maymeow","custom":"https://www.buymeacoffee.com/maymeow"}},"created_at":"2018-05-07T18:09:34.000Z","updated_at":"2023-01-17T10:08:10.000Z","dependencies_parsed_at":"2023-01-14T21:06:19.167Z","dependency_job_id":null,"html_url":"https://github.com/MayMeow/php-encrypt","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MayMeow%2Fphp-encrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MayMeow%2Fphp-encrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MayMeow%2Fphp-encrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MayMeow%2Fphp-encrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MayMeow","download_url":"https://codeload.github.com/MayMeow/php-encrypt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220097252,"owners_count":16594112,"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":["certificates","encryption","hacktoberfest","hacktoberfest2020","library","openssl","php","security"],"created_at":"2024-10-01T16:51:25.459Z","updated_at":"2024-10-17T16:03:24.877Z","avatar_url":"https://github.com/MayMeow.png","language":"PHP","funding_links":["https://github.com/sponsors/maymeow","https://www.buymeacoffee.com/maymeow"],"categories":[],"sub_categories":[],"readme":"If you like this package, please note that it is no longer in active development and please check [PHP-Cryphography](https://github.com/MayMeow/php-cryptography) package.\n\n# PHP Encrypt\n\nThis is readonly Mirror however you can still conttibute if you have email. For more infomation scroll down to **Contributing**.\n\nLibrary for signing certificates with selfsigned CA\n\n![](https://github.com/maymeow/php-encrypt/workflows/PHP%20Composer/badge.svg)\n[![Maintainability](https://api.codeclimate.com/v1/badges/6b389f3bda3f42dd467a/maintainability)](https://codeclimate.com/github/MayMeow/php-encrypt/maintainability)\n\n## Installation\n\nInstall with docker:\n```bash\ncomposer require maymeow/php-encrypt\n```\n\nAnd intialize it withhin your script\n```php\n$cf = new \\MayMeow\\Factory\\CertificateFactory(new \\MayMeow\\Model\\EncryptConfiguration());\n```\n\n### Alternative you can download from my private server\n\nadd to your composer.json files to repositories section\n\n```json\n{\"type\":\"composer\",\"url\":\"https://git.cloud.hsoww.net/api/v4/group/121/-/packages/composer/packages.json\"}\n```\n\n## Usage [WIP]\n\n### Path Configuring\n\nTo set diferent path for cert templates (cnf files) use:\n\n```php\n// dont forget to use trailing slash\n$cf = new \\MayMeow\\Factory\\CertificateFactory(new \\MayMeow\\Model\\EncryptConfiguration(), '/path/to/templates/folder/');\n```\n\nTo chanage folder to change path to your configuration file\n\n```php\n// use full path to your configuration file include name of this file\n$cf = new \\MayMeow\\Factory\\CertificateFactory(new \\MayMeow\\Model\\EncryptConfiguration('/path/to/templates/folder/my_config_file.yml'));\n```\n\n### Certificate Signing - [DEPRECATED]\n\n1. Create Selfsigned CA\n\n```php\nuse MayMeow\\Writers\\FileWriter;\n\n$cf-\u003edomainName()\n    -\u003esetOrganizationName('Hogwarts School of Witchcraft and Wizardry')\n    -\u003esetCountryName('SK')\n    -\u003esetCommonName('Hogwarts School of Witchcraft and Wizardry Root CA');\n\n$cf-\u003esetType('ca')\n    -\u003esetName('Hogwarts')\n    -\u003esign()\n    -\u003ewriteTo(FileWriter::class);\n```\n\n2. Create Intermediate CAs. This type of CA you will use for signing users and servers certificates.\n\n```php\nuse MayMeow\\Writers\\FileWriter;\nuse MayMeow\\Loaders\\FileLoader;\n\n$cf-\u003edomainName()\n    -\u003esetOrganizationName('Hogwarts School of Witchcraft and Wizardry')\n    -\u003esetCountryName('SK')\n    -\u003esetOrganizationalUnitName('Hogwarts houses')\n    -\u003esetCommonName('Slytherin HSoWaW House');\n\n$cf-\u003esetType('intermediate')\n    -\u003esetName('Hogwarts/Slytherin')\n    -\u003esetCaFrom(new FileLoader('test-ca'))\n    -\u003esign()-\u003ewriteTo(FileWriter::class);\n```\n\n3. Sign User or server certificate\n\n* User Certificate\n\n```php\nuse MayMeow\\Writers\\FileWriter;\nuse MayMeow\\Loaders\\FileLoader;\n\n$cf-\u003edomainName()\n    -\u003esetCommonName('Hermione Granger')\n    -\u003esetEmailAddress('hermione.granger@g.hogwarts.local')\n    -\u003esetOrganizationName('Hogwarts School of Witchcraft and Wizardry')\n    -\u003esetOrganizationalUnitName('Hogwarts Students');\n\n$cf-\u003esetType('user')\n    -\u003esetName('Hogwarts/Students/hermione-granger')\n    -\u003esetCaFrom(new FileLoader('test-ca'))\n    -\u003esign()-\u003ewriteTo(FileWriter::class);\n```\n\n* Server Certificate\n\n```php\nuse MayMeow\\Writers\\FileWriter;\nuse MayMeow\\Loaders\\FileLoader;\n\n$cf-\u003edomainName()\n    -\u003esetCommonName(\"gryffindor.hogwarts.local\")\n    -\u003esetOrganizationalUnitName(\"Hogwarts Webpages\")\n    -\u003esetOrganizationName(\"Hogwarts School of Witchcraft and Wizardry\");\n\n$cf-\u003egetAltNames()\n    -\u003esetDns(\"gryffindor.hogwarts.local\")\n    -\u003esetDns(\"*.gryffindor.hogwarts.local\")\n    -\u003esetIp(\"10.0.20.2\");\n\n$cf-\u003esetType(\"server\")\n    -\u003esetName(\"Hogwarts/Webpages/griffindor-hogwarts-local\")\n    -\u003esetCaFrom(new FileLoader('test-ca'))\n    -\u003esign()-\u003ewriteTo(FileWriter::class);\n```\n\n4. Each certificatess are located in `webroot/\u003ccertificate-name\u003e`. Certificate Names can be set\nwith `-\u003esetName(\u003ccertificate-name\u003e)` function.\n5. To load CA for signing certificate you will use `-\u003esetCa(\u003ccertificate-name\u003e, \u003ccertificate-key-pass\u003e)`.\n__Certificate Key pass__ is located in `code.txt` file in each certificate folder.\n\n### PKCS12 file format\n\nWindows users need certificate in PKCS12 format, `.pfx` file extension. To create this type of file use\n\n```php\n// public function write($decryptPK = false, $pcks12 = false);\n...-\u003ewrite(false, true);\n```\n\n### Creating key pairs\n\nIf you dont need certificate you can create key pair `from v2018.4` updated in `v2019.5`\n\n```php\nuse MayMeow\\RSA\\RSACryptoServiceProvider;\n\n$this-\u003ecsp = new RSACryptoServiceProvider();\n$keypair = $this-\u003ecsp-\u003egenerateKeyPair('yourSuperStrongPas$$phrase'); // returns RSAParameters\n\n// privateKey \u0026 public key\n$keypair-\u003egetPrivateKey();\n$keypair-\u003egetPublicKey();\n```\n\n### Loaders [DEPRECATED]\n\nAre now deprecated and will be removed in nex major release\n\n```php\nuse MayMeow\\Loaders\\FileLoader;\n\n$kp = new FileLoader('test-ca');\n$kp-\u003egetPublicKey();\n$kp-\u003egetPrivateKey();\n```\n\n## Crypto Service Providers\n\n### RSA Crypto Service Provider\n\nRSACSP is replace Security factory. It's used for asymetric encryption. Asymetric encryption is using two keys, public for encrypt and private key for decrypt data;\n\n```php\n// Generate keypPairs\nuse MayMeow\\Cryptography\\RSA\\RSACryptoServiceProvider;\nuse MayMeow\\Cryptography\\Filesystem\\RsaParametersFileLoader;\n\n$this-\u003ecsp = new RSACryptoServiceProvider();\n\n// generate new keypairs\n$keypair = $this-\u003ecsp-\u003egenerateKeyPair('yourSuperStrongPas$$phrase'); // returns RSAParameter\n\n// OR Load keypairs from file\n$fileLoader = new RsaParametersFileLoader();\n$this-\u003ecsp-\u003esetRsaParameters($fileLoader-\u003eload('name_of_certificate'));\n\n// Ecrypt and decrypt\n$plainText = 'Hello World!';\n$encryptedText = $this-\u003ecsp-\u003eencrypt($plainText);\n$decrypted = $this-\u003ecsp-\u003edecrypt($encryptedText);\n\n// Signing\n$signature = $this-\u003ecsp-\u003esign($plainText);\n$this-\u003ecsp-\u003everify($plainText, $signature); // true or false\n\n// md5 fingerprint\n$this-\u003ecsp-\u003egetFingerPrint();\n```\n\n### AES Crypto Service Provider\n\nAESCSP is using for aes encryption. Aes is symetric encryption, is using only one key for encrypt/decrypt data. For more security it can be used together with asymetric encryption.\n\n```php\nuse MayMeow\\Cryptography\\AES\\AESCryptoServiceProvider;\n\n//initialize CSP, generate key and IV\n$csp = new AESCryptoServiceProvider();\n$csp-\u003egenerateIV();\n$key = $csp-\u003egenerateKey();\n\n//encrypt data\n$plainText = \"This is going to be encrypted!\";\n$encryptedText = $this-\u003ecsp-\u003eencrypt($plainText);\n\n// inistialize another CSP\n// sure you can use same instance to decrypt but in most cases you only ancrypting\n// and then storing to database to decrypt it later\n$csp2 = new AESCryptoServiceProvider();\n$csp2-\u003esetKey($key); // et key you generated before\n\n//decrypt text\n$originalText = $csp2-\u003edecrypt($encryptedText);\n```\n\n## Contributing\n\nThis repository is mirror from my own git server. If you want to contribute you will need email.\n\n1. Create new branch\n\n``` bash\nit checkout -b \u003cyour branch name\u003e\n```\n\n2. Create new commit from your changes and make patch.\n\n``` bash\ngit add \u003cfile\u003e\ngit commit\ngit format-patch -o /tmp/ HEAD^\n```\n\n3. Send you patch to my email.\n\n**DO NOT** make changes right inside master branch. I will not accept that.\n\n\n## History\n\nSEE changelog\n\n## Credits\n\n* [MayMeow (Emma)](https://github.com/MayMeow)\n\n## Stargazers\n\n[![Stargazers repo roster for @MayMeow/php-encrypt](https://reporoster.com/stars/MayMeow/php-encrypt)](https://github.com/MayMeow/php-encrypt/stargazers)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaymeow%2Fphp-encrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaymeow%2Fphp-encrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaymeow%2Fphp-encrypt/lists"}