Download the PHP package ricwein/crypto without Composer
On this page you can find all versions of the php package ricwein/crypto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package crypto
Crypto
This library wraps the PHP libsodium cryptographic functions into an object-orientated api, allowing a simple and safe usage.
This library provides:
- symmetric and asymmetric authenticated en/decryption of messages and files using XSalsa20
- cryptographic secure key and keypair generation
- Diffie Hellman key-exchange for keypairs using Curve25519 (X25519)
- ex/import of keys and ciphertexts with support for most common encodings
Installation
All classes uses the root-namespace ricwein\Crypto
. All thrown Exceptions extend from ricwein\Crypto\Exceptions\Exception
.
Symmetric Crypto
Symmetric cryptography uses a secret (key) to encrypt a given message to a ciphertext, and the same secret to decrypt the ciphertext to the original message again.
encrypt
decrypt
Asymmetric Crypto
Asymmetric Crypto uses keypairs out of a public, and a private key to encrypt and sign messages.
sending: Usually a Message is encrypted with the public-key of the receiver, and signed with the private-key of the sender.
receiving: The receiver is than able to verify the message-signature ((H)MAC) with the public-key of the sender and can decrypt it with its own private-key.
The following example uses two keypairs (alice and bob) with known private-keys in the same code-scope. This is just done for comprehensibility. In real-world cases on side only knowns it's own private-key (public is not required) and the public-key of the other participant.
encrypt
decrypt
Encoding
Key-ex/import and ciphertext ex/import supports four types of encoding, provided by ricwein\Crypto\Encoding
.
File-Crypto
This library also provides RAM-friendly file-en/decrypting using stream-encryption. To use the integrated file-crypto, the ricwein/filesystem
library is required. It can be installed with:
The usage is the same as the sym/asymmetric en/decryption methods, but instead of encrypting strings into ciphertexts-objects, a File will be encrypted, returning a new File-Object.
Most times it's useful to encrypt a file and replace its plaintext with the new ciphertext. It should be noted, that this library creates a temp-file in this case, encrypts the sourcefile into the new temp-file, and replaces the source afterwards with the temp-file.
All file-crypto methods support custom destination storages, which can be provided as the last parameter in encryptFile()
and decryptFile()
. If a storage is given, the previously described encryption through a temp-file is skipped.
Symmetric Crypto
encrypt
decrypt
Asymmetric Crypto
The following example uses two keypairs (alice and bob) with known private-keys in the same code-scope. This is just done for comprehensibility. In real-world cases, one side only knows its own private-key (public is not required) and the public-key of the other participant.
encrypt
decrypt
All versions of crypto with dependencies
ext-mbstring Version *
ext-sodium Version *
paragonie/constant_time_encoding Version ^2