Download the PHP package spatie/crypto without Composer
On this page you can find all versions of the php package spatie/crypto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spatie/crypto
More information about spatie/crypto
Files in spatie/crypto
Package crypto
Short Description Encrypting and signing data using private/public keys
License MIT
Homepage https://github.com/spatie/crypto
Informations about the package crypto
Encrypting and signing data using private/public keys
This package allows you to easily generate a private/public key pairs, and encrypt/decrypt messages using those keys.
Most functions in this package are wrappers around openssl_*
functions to improve DX.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
Usage
You can generate a key pair using the generate
function on the KeyPair
class.
You can write the keys to disk, by passing paths to the generate
function.
You can protect the private key with a password by using the password
method:
When using a password to generating a private key, you will need that password when instantiating the PrivateKey
class.
Loading keys
To load a key from a file use the fromFile
static method.
Alternatively, you can also create a key object using a string.
If the private key is password protected, you need to pass the password as the second argument.
If you do not specify the right password, a Spatie\Crypto\Exceptions\InvalidPrivateKey
exception will be thrown.
Encrypting a message with a private key, decrypting with the public key
Here's how you can encrypt data using the private key, and how to decrypt it using the public key.
If decrypt
cannot decrypt the given data (maybe a non-matching private key was used to encrypt the data, or maybe tampered with the data), an exception of class Spatie\Crypto\Exceptions\CouldNotDecryptData
will be thrown.
Encrypting a message with a public key, decrypting with the private key
Here's how you can encrypt data using the public key, and how to decrypt it using the private key.
If decrypt
cannot decrypt the given data (maybe a non-matching public key was used to encrypt the data, or maybe tampered with the data), an exception of class Spatie\Crypto\Exceptions\CouldNotDecryptData
will be thrown.
Determining if the data can be decrypted
Both the PublicKey
and PrivateKey
class have a canDecrypt
method to determine if given data can be decrypted.
Signing and verifying data
The PrivateKey
class has a method sign
to generate a signature for the given data. The verify
method on the PublicKey
class can be used to verify if a signature is valid for the given data.
If verify
returns true
, you know for certain that the holder of the private key signed the message, and that it was not tampered with.
Alternatives
This package aims to be very lightweight and easy to use. If you need more features, consider using of one these alternatives:
A word on the usage of RSA
At the time of writing, RSA is secure enough for the use case we've built this package for.
To know more about why RSA might not be good enough for you, read this post on public-key encryption at Paragonie.com
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Freek Van der Herten
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of crypto with dependencies
ext-openssl Version *