provides object-oriented, secure and extended access to PHP OpenSSL functions
The OpenSSL pkey functions are assembled in the
The OpenSSL CSR functions are assembled in the
The OpenSSL x509 functions are assembled in the
The OpenSSL pkcs7 functions are assembled in the
The OpenSSL pkcs12 functions are assembled in the
The OpenSSL spki functions are assembled in the
Remaining OpenSSL functions are assembled in the
Asserts and convenient salt, base64, hex, pack utility etc methods are assembled in the
All methods have
Method names originates from OpenSSL function names
Most methods has also more convenient and describable named method alias
Most methods (ex setters) are chainable (ie return 'static')
The OO-classes, above, has 'factory' methods, support 'one-liners' and inherit usefull constants defind in the OpenSSLInterface
Supplementary methods for message digest / hmac digest support are assembled in the
* HashFactory class * HmacHashFactory class
Generate keys :
<?php
namespace Kigkonsult\OpenSSLToolbox;
$config = [
OpenSSLPkeyFactory::DIGESTALGO => OPENSSL_ALGO_SHA512,
OpenSSLPkeyFactory::PRIVATEKEYBITS => 4096,
OpenSSLPkeyFactory::PRIVATEKEYTYPE => OPENSSL_KEYTYPE_RSA,
];
$pKeyFactory = new OpenSSLPkeyFactory( $config );
// Generate a private key
$privateKeyString = $pKeyFactory->getPrivateKeyAsPemString();
// Generate a public key
$publicKeyString = $pKeyFactory->getPublicKeyAsPemString();
/*
// or
list( $privateKeyString, $publicKeyString ) =
$pKeyFactory->getPrivatePublicKeyPairAsPemStrings();
// or one-liner, all-in-one
list( $privateKeyString, $publicKeyString ) =
OpenSSLPkeyFactory::factory( $config )
->getPrivatePublicKeyPairAsPemStrings();
// or to files
OpenSSLPkeyFactory::factory( $config )
->savePrivatePublicKeyPairIntoPemFiles( 'priv.pem', 'pub.pem' )
*/
// Distinguished Name or subject fields to be used in the certificate
$DN = [
OpenSSLCsrFactory::COUNTRYNAME => "GB",
OpenSSLCsrFactory::STATEORPROVINCENAME => "Somerset",
OpenSSLCsrFactory::LOCALITYNAME => "Glastonbury",
OpenSSLCsrFactory::ORGANIZATIONNAME => "The Brain Room Limited",
OpenSSLCsrFactory::ORGANIZATIONUNITNAME => "PHP Documentation Team",
OpenSSLCsrFactory::COMMONNAME => "Wez Furlong",
OpenSSLCsrFactory::EMAILADDRESS => "wez@example.com"
];
// Generate a certificate signing request
$csrFactory = OpenSSLCsrFactory::factory( $DN, $privateKeyString, $config );
$csrCertString = $csrFactory->getCSRasPemString();
// Generate a self-signed cert
$x509CertResource = $csrFactory->getX509CertResource( null, $privateKeyString );
$x509Factory = OpenSSLX509Factory::factory()
->setX509Resource( $x509CertResource );
$x509CertString = $x509Factory->getX509CertAsPemString();
/*
// or shorter
$x509CertString = OpenSSLX509Factory::csrFactory( null, $DN, $privateKeyString, $config )
->getX509CertAsPemString();
// or save to pem/der-file
OpenSSLX509Factory::csrFactory( null, $DN, $privateKeyString, $config )
->saveX509CertIntoPemFile( 'cert.pem' );
// ->saveX509CertIntoDerFile( 'cert.der' )
*/
Seal/open
<?php
...
// Seal data using public key(s)
$data = implode( array_fill( 0, 100, 'Testing OpenSSL seal/open, !"#¤%&/()=?. '));
$recipientId = 'The Recipient';
$publicKeys = [ $recipientId => $publicKeyString ];
list( $sealed, $envelopeKeys ) = OpenSSLFactory::getSealedString( $data, $publicKeys );
// Open (decrypted) data using private key
$decrypted = OpenSSLFactory::getOpenedSealedString(
$sealed, $envelopeKeys[$recipientId], $privateKeyString
);
Encrypt/decrypt
$data = implode( array_fill( 0, 100, 'Testing OpenSSL encrypt/decrypt, !"#¤%&/()=?. '));
$cipher = 'AES-256-ECB';
$passPhrase = Workshop::getSalt();
// encrypt string
$encrypted = OpenSSLFactory::getEncryptedString( $data, $cipher, $passPhrase );
// decrypt string
$decrypted = OpenSSLFactory::getDecryptedString( $encrypted, $cipher, $passPhrase );
More encrypt/decrypt
$data = 'Testing OpenSSL public/private encrypt/decrypt, !"#¤%&/()=?. ';
// Encrypt the data using the PUBLIC key
$encrypted = OpenSSLFactory::getpublicKeyEncryptedString( $data, $publicKeyString );
// Decrypt the data using the PRIVATE key
$decrypted = OpenSSLFactory::getprivateKeyDecryptedString( $encrypted, $privateKeyString );
// Encrypt the data using the PRIVATE key
$encrypted = OpenSSLFactory::getprivateKeyEncryptedString( $data, $privateKeyString );
// Decrypt the data using the PUBLIC key
$decrypted = OpenSSLFactory::getpublicKeyDecryptedString( $encrypted, $publicKeyString );
You will find - class information in docs folder - convenient constants in src/OpenSSLInterface - a lot of more examples in the test folder.
From the Command Line:
composer require kigkonsult/openssltoolbox
In your composer.json
:
{
"require": {
"kigkonsult/openssltoolbox": "dev-master"
}
}
Acquire access
namespace Kigkonsult\OpenSSLToolbox;
...
include 'vendor/autoload.php';
Download and acquire..
namepace Kigkonsult\OpenSSLToolbox;
...
include 'pathToSource/OpenSSLToolbox/autoload.php';
Run tests
cd pathToSource/OpenSSLToolbox
vendor/bin/phpunit
Note, it will takes some time, 80% coverage...<br> But still remain untested parts, help appreciated.
For support, please use [Github]/issues.
This project is licensed under the LGPLv3 License
[Composer]:https://getcomposer.org/ [Github]:https://github.com/iCalcreator/OpenSSLToolbox/issues
Classes of Kjell-Inge Gustafsson | > | PHP OpenSSL Toolbox | > | Download .zip .tar.gz | > | Support forum | > | Blog | > | Latest changes |
|
|
Groups | Applications | Files |
Groups |
PHP 5 | Classes using PHP 5 specific features | View top rated classes |
Files and Folders | Listing, accessing and manipulating files and folders | View top rated classes |
Cryptography | Encrypting, decrypting and hashing data | View top rated classes |
Security | Security protection and attack detection | View top rated classes |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
File | Role | Description | ||
---|---|---|---|---|
docs (17 files) | ||||
src (18 files) | ||||
test (20 files, 1 directory) | ||||
autoload.php | Aux. | Auxiliary script | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Read me |
Files | / | docs |
File | Role | Description |
---|---|---|
Assert.md | Data | Auxiliary data |
Convert.md | Data | Auxiliary data |
docs.md | Data | Auxiliary data |
HashFactory.md | Data | Auxiliary data |
HmacHashFactory.md | Data | Auxiliary data |
lgpl.txt | Doc. | Documentation |
OpenSSLBase.md | Data | Auxiliary data |
OpenSSLBaseFactory.md | Data | Auxiliary data |
OpenSSLCryptor.md | Data | Auxiliary data |
OpenSSLCsrFactory.md | Data | Auxiliary data |
OpenSSLFactory.md | Data | Auxiliary data |
OpenSSLPkcs12Factory.md | Data | Auxiliary data |
OpenSSLPkcs7Factory.md | Data | Auxiliary data |
OpenSSLPkeyFactory.md | Data | Auxiliary data |
OpenSSLSpkiFactory.md | Data | Auxiliary data |
OpenSSLX509Factory.md | Data | Auxiliary data |
Workshop.md | Data | Auxiliary data |
Files | / | src |
File | Role | Description |
---|---|---|
Assert.php | Class | Class source |
BaseFactory.php | Class | Class source |
Convert.php | Class | Class source |
HashFactory.php | Class | Class source |
HmacHashFactory.php | Class | Class source |
OpenSSLBaseFactory.php | Class | Class source |
OpenSSLBaseFactory2.php | Class | Class source |
OpenSSLCryptor.php | Class | Class source |
OpenSSLCsrFactory.php | Class | Class source |
OpenSSLFactory.php | Class | Class source |
OpenSSLInterface.php | Class | Class source |
OpenSSLPkcs12Factory.php | Class | Class source |
OpenSSLPkcs7Factory.php | Class | Class source |
OpenSSLPkeyFactory.php | Class | Class source |
OpenSSLSpkiFactory.php | Class | Class source |
OpenSSLX509Factory.php | Class | Class source |
PhpErrorException.php | Class | Class source |
Workshop.php | Class | Class source |
Files | / | test |
File | Role | Description | ||
---|---|---|---|---|
Traits (3 files) | ||||
AssertTest.php | Class | Class source | ||
BaseFactoryTest.php | Class | Class source | ||
BaseTest.php | Class | Class source | ||
ConvertTest.php | Class | Class source | ||
HashFactoryTest.php | Class | Class source | ||
HmacHashFactoryTest.php | Class | Class source | ||
OpenSSLBaseFactory2Test.php | Class | Class source | ||
OpenSSLBaseFactoryTest.php | Class | Class source | ||
OpenSSLCryptorTest.php | Class | Class source | ||
OpenSSLCsrFactoryTest.php | Class | Class source | ||
OpenSSLDemoTest.php | Class | Class source | ||
OpenSSLFactoryTest.php | Class | Class source | ||
OpenSSLPkcs12FactoryTest.php | Class | Class source | ||
OpenSSLPkcs7FactoryTest.php | Class | Class source | ||
OpenSSLPkeyFactoryTest.php | Class | Class source | ||
OpenSSLSpkiFactoryTest.php | Class | Class source | ||
OpenSSLTest.php | Class | Class source | ||
OpenSSLX509FactoryTest.php | Class | Class source | ||
PhpErrorExceptionTest.php | Class | Class source | ||
WorkshopTest.php | Class | Class source |
Files | / | test | / | Traits |
File | Role | Description |
---|---|---|
assertMdCipherAlgorithmTrait.php | Class | Class source |
CsrX509Trait.php | Class | Class source |
PkeySealOpenTrait.php | Class | Class source |
Download all files: openssltoolbox.tar.gz openssltoolbox.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|