Skip to content
/ cipher Public

Cipher: A tool for easier working with cryptography for PHP language

License

Notifications You must be signed in to change notification settings

phiCorp/cipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cipher

A tool for easier working with cryptography for PHP language

Installation

Install Cipher with composer

composer require phicorp/cipher

Features

  • Easy to use
  • Symmetric encryption and decryption with powerful AES algorithm
  • Asymmetric encryption and decryption with RSA algorithm
  • A variety of hash algorithms such as SHA and Bcrypt
  • And more features

Usage/Examples

  • Symmetric encryption and decryption:
$key = Cipher::AESKEY();
$iv = Cipher::AESIV();

$plaintext = 'Hello World!';

$ciphertext = encrypt($plaintext, $key, $iv);

$decryptedText = decrypt($ciphertext, $key, $iv);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";

Or

$key = Cipher::AESKEY();
$iv = Cipher::AESIV();

$plaintext = 'Hello World!';

$ciphertext = Cipher::AES()->key($key)->iv($iv)->encrypt($plaintext);

$decryptedText = Cipher::AES()->key($key)->iv($iv)->decrypt($ciphertext);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";
  • GCM Mode symmetric encryption and decryption
$key = Cipher::AESKEY("AES-256-GCM");
$iv = Cipher::AESIV();
$tag = null;

$plaintext = 'Hello World!';

$ciphertext = Cipher::AES('GCM')->key($key)->iv($iv)->encrypt($plaintext, 0, $tag);

$decryptedText = Cipher::AES('GCM')->key($key)->iv($iv)->decrypt($ciphertext, 0, $tag);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";

  • Examples for asymmetric encryption and decryption
[$publicKey, $privateKey] = Cipher::RSAKEY();

$plaintext = 'hello world!';

$ciphertext = RSA($publicKey, $privateKey)->encryptPublic($plaintext);
$decryptedText = RSA($publicKey, $privateKey)->decryptPrivate($ciphertext);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";

// You can also use it in this way

[$publicKey, $privateKey] = Cipher::RSAKEY();

$plaintext = 'hello world!';

$ciphertext = Cipher::RSA()->privateKey($privateKey)->encryptPrivate($plaintext);
$decryptedText = RSA()->publicKey($publicKey)->decryptPublic($ciphertext);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";

  • Example of using hash functions
sha512('Hello World!');
//output: 861844d6704e...
sha256('Hello World!');
//output: 7f83b1657ff1...
$hash = bcrypt('password', 15);

var_dump(bcrypt_verify('password', $hash));
// output: true

Authors

License

MIT