2017 © Pedro Peláez
 

library cipher

Cipher, an easy method to encrypt and decrypt

image

peterurk/cipher

Cipher, an easy method to encrypt and decrypt

  • Tuesday, January 20, 2015
  • by peterurk
  • Repository
  • 2 Watchers
  • 2 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Cipher

A simple PHP library to encrypt and decrypt strings. The library supports AES-256-CBC and AES-256-GCM and requires PHP 8.1 or higher., (*1)

Installation

Install the package through Composer:, (*2)

composer require peterurk/cipher

Usage

use peterurk\Cipher\Cipher;

$cipher = new Cipher('YourSecretKey');

$encrypted = $cipher->encrypt('message');
$decrypted = $cipher->decrypt($encrypted);

Using environment variables

You can provide the key and cipher method through environment variables:, (*3)

export CIPHER_KEY=mysecret
export CIPHER_METHOD=AES-256-GCM
export CIPHER_SALT=mysalt
$cipher = new Cipher();

The defaults for the cipher method, tag length and salt are configurable via constants in Cipher., (*4)

Security considerations

AES-256-CBC is vulnerable to tampering if you do not verify integrity. Enable the --hmac option or pass true as the third constructor argument to automatically append and validate an HMAC. AES-256-GCM already provides authentication and does not need HMAC., (*5)

CLI

This repository ships with a small CLI tool. Show the help message:, (*6)

bin/cipher --help

Encrypt a string:, (*7)

bin/cipher --encrypt "hello" --key mysecret

Decrypt a string:, (*8)

bin/cipher --decrypt "<ciphertext>" --key mysecret

File encryption

$cipher->encryptFile('input.txt', 'output.enc');
$cipher->decryptFile('output.enc', 'plain.txt');

Encrypt a file from the CLI:, (*9)

bin/cipher --encrypt-file input.txt --key mysecret > output.enc

Decrypt a file from the CLI:, (*10)

bin/cipher --decrypt-file output.enc --key mysecret > plain.txt

Large files are processed in chunks so they won't consume excessive memory., (*11)

Running Tests

composer install
composer test

License

Released under the MIT License., (*12)

The Versions

20/01 2015

dev-master

9999999-dev https://github.com/peterurk/Cipher

Cipher, an easy method to encrypt and decrypt

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Peter Post

encryption cipher decryption