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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package crypto

Encrypting and signing data using private/public keys

Latest Version on Packagist Tests Total Downloads

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

License

The MIT License (MIT). Please see License File for more information.


All versions of crypto with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
ext-openssl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spatie/crypto contains the following files

Loading the files please wait ....