maymeow / may-encrypt
Extendable Certificate Authority scirpt made with PHP
Installs: 354
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 1
Type:project
Requires
- symfony/yaml: ^4.0
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2019-02-20 19:30:33 UTC
README
Library for signing certificates with selfsigned CA
Installation
Install with docker:
composer require maymeow/may-encrypt
And intialize it withhin your script
$cf = new \MayMeow\Factory\CertificateFactory();
Usage
Path Configuring
To Set different Root path for generated certificates use
$cf->setDataPath('/your/path/to/folder');
If you want to save templates for generating certificates on different folder you can set this path with:
$cf->setTemplatesPath('/path/to/templates/folder');
If you don use any of this commands default values will be used.
Certificate Signing
- Create Selfsigned CA
$cf->domainName() ->setOrganizationName('Hogwarts School of Witchcraft and Wizardry') ->setCountryName('SK') ->setCommonName('Hogwarts School of Witchcraft and Wizardry Root CA'); $cf->setType('ca') ->setName('Hogwarts') ->sign()->toFile();
- Create Intermediate CAs. This type of CA you will use for signing users and servers certificates.
$cf->domainName() ->setOrganizationName('Hogwarts School of Witchcraft and Wizardry') ->setCountryName('SK') ->setOrganizationalUnitName('Hogwarts houses') ->setCommonName('Slytherin HSoWaW House'); $cf->setType('intermediate') ->setName('Hogwarts/Slytherin') ->setCa('Hogwarts', '200634') ->sign()->toFile();
- Sign User or server certificate
- User Certificate
$cf->domainName() ->setCommonName('Hermione Granger') ->setEmailAddress('hermione.granger@g.hogwarts.local') ->setOrganizationName('Hogwarts School of Witchcraft and Wizardry') ->setOrganizationalUnitName('Hogwarts Students'); $cf->setType('user') ->setName('Hogwarts/Students/hermione-granger') ->setCa('Hogwarts/Gryffindor', '296545') ->sign()->toFile(true);
- Server Certificate
$cf->domainName() ->setCommonName("gryffindor.hogwarts.local") ->setOrganizationalUnitName("Hogwarts Webpages") ->setOrganizationName("Hogwarts School of Witchcraft and Wizardry"); $cf->getAltNames() ->setDns("gryffindor.hogwarts.local") ->setDns("*.gryffindor.hogwarts.local") ->setIp("10.0.20.2"); $cf->setType("server") ->setName("Hogwarts/Webpages/griffindor-hogwarts-local") ->setCa('Hogwarts/Gryffindor', '296545') ->sign()->toFile();
- Each certificatess are located in
webroot/<certificate-name>
. Certificate Names can be set with->setName(<certificate-name>)
function. - To load CA for signing certificate you will use
->setCa(<certificate-name>, <certificate-key-pass>)
. Certificate Key pass is located incode.txt
file in each certificate folder.
PKCS12 file format
Windows users need certificate in PKCS12 format, .pfx
file extension. To create this type of file use
...->toFile(true);
Creating key pairs
If you dont need certificate you can create key pair from v2018.4
$keys = $cf->setType('ca')->setName('keys-2')->getKeyPair(true); // true means keys will be stored into files $keys->getPrivateKey(); // returns private key $keys->getPublicKey(); // returns public key
Security factory
Security factory can be used for encryptig and decripting strings.
- Initialize security factory
$sf = new \MayMeow\Factory\SecurityFactory(new \MayMeow\Factory\CertificateFactory());
- Set string which you want to encrypt
$string = json_encode([ "name" => 'Hello', "surname" => 'world' ]); $sf->setString($string);
- load keys that will be used to encrypt / decrypt
$sf->setPrivateKey('keys-2', null); $sf->setPublicKey('keys-2');
or you can use loaders to set keypairs
$sf->setKeyPair(new KeyPairFileLoader('keys-2'));
- Encrypt text
$enc = base64_encode($sf->publicEncrypt());
- Decrypt
$sf->setString(base64_decode($enc)); $decrypted = base64_encode($sf->privateDecrypt());
Example above will encrypt text with public key and decrypt with private. If you want encrypt with private just use $sf->encrypt()
and $sf->decrypt
for decrypting.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
History
SEE changelog
Credits
- MayMeow
- mARTin
License
MIT
Support on Beerpay
Hey dude! Help me out for a couple of 🍻!