<?php
error_reporting(1);
ini_set('display_errors', 1);
class Encryption {
private $key;
protected $iv_size;
protected $iv;
public function __construct() {
# --- ENCRYPTION ---
# the key should be random binary, use scrypt, bcrypt or PBKDF2 to
# convert a string into a key
# key is specified using hexadecimal
$this->key = pack("H*", "myKeyIsGreaterth2nanndbestofall04nkdsdffsd546754sdfvsdg6efflsdfs");
# create a random IV to use with CBC encoding
$this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
}
public function encryptData($input) {
$output = $this->encrypt($input);
return $output;
}
public function decryptData($input) {
$input = base64_decode($input);
$output = $this->decrypt($input);
return $output;
}
public function decrypt($string) {
# retrieves the IV, iv_size should be created using mcrypt_get_iv_size()
$iv_dec = substr($string, 0, $this->iv_size);
# retrieves the cipher text (everything except the $iv_size in the front)
$string = substr($string, $this->iv_size);
# may remove 00h valued characters from end of plain text
$output = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $string, MCRYPT_MODE_CBC, $iv_dec);
return $output;
}
public function encrypt($string) {
# creates a cipher text compatible with AES (Rijndael block size = 128)
# to keep the text confidential
# only suitable for encoded input that never ends with value 00h
# (because of default zero padding)
$output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $string, MCRYPT_MODE_CBC, $this->iv);
# prepend the IV for it to be available for decryption
$output = $this->iv . $output;
# encode the resulting cipher text so it can be represented by a string
$output = base64_encode($output);
# === WARNING ===
# Resulting cipher text has no integrity or authenticity added
# and is not protected against padding oracle attacks.
return $output;
}
}
$test = new Encryption();
$encrypted = $test->encryptData("Narendra");
echo "This is encrypted text of a string Narendra => $encrypted \n";
echo "This is decrypted text => ".$test->decryptData($encrypted);
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/HRI03:19
Stack trace:
#0 /in/HRI03(70): Encryption->__construct()
#1 {main}
thrown in /in/HRI03 on line 19
Process exited with code 255.
Output for 7.0.5
This is encrypted text of a string Narendra => vO9M0mE4luXKE4CAFSEr5/KBsuxPRn3O5FxQvs6J6Ck=
This is decrypted text => Narendra
Output for 7.0.4
This is encrypted text of a string Narendra => 6An6zkGUq2kv8WGe4Jg31vyBbILPTKiAtVloTnlZyLc=
This is decrypted text => Narendra
Output for 7.0.3
This is encrypted text of a string Narendra => ylb4mByIKNvte1cQWoe5JDgcw4W7Y0EtCbxdH1YQ+A4=
This is decrypted text => Narendra
Output for 7.0.2
This is encrypted text of a string Narendra => jJAht+ZduPzswYHY2hCwJorw/OqowTFvtHMrNRQ+K3g=
This is decrypted text => Narendra
Output for 7.0.1
This is encrypted text of a string Narendra => oVdwJx6VXW0iilM0XHN3JgpwnMiH9x/dR16qM50VXmg=
This is decrypted text => Narendra
Output for 7.0.0
This is encrypted text of a string Narendra => MQH83IKGEVp6lQ5F8mdbanuLv3WHCqOi0BjcjGglPFk=
This is decrypted text => Narendra
Output for 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/HRI03 on line 19
Process exited with code 255.
Output for 5.6.20
This is encrypted text of a string Narendra => aYS9gaFJk7F5XA54twqFhzCsOLfEW9nb620oB6WNcMw=
This is decrypted text => Narendra
Output for 5.6.19
This is encrypted text of a string Narendra => HM8XG9bSJ2NyzZQcDi7TDlb3GKavjLajKXLhO9IxMWA=
This is decrypted text => Narendra
Output for 5.6.18
This is encrypted text of a string Narendra => j6mQuwEeMDXTxnP9334AgjGdAPHLe8oEkdlwuMMlXck=
This is decrypted text => Narendra
Output for 5.6.17
This is encrypted text of a string Narendra => QaCnE5BFTB0X3CtEDODysF4nAgVNGyo7lFd74S/Opfw=
This is decrypted text => Narendra
Output for 5.6.16
This is encrypted text of a string Narendra => tsYQ3aLUsg2n+qRIiH7FVoy02/aux88ZekxA7Ehgrew=
This is decrypted text => Narendra
Output for 5.6.15
This is encrypted text of a string Narendra => qYJxN0Ze8zo5gVTpptA+HSLM6gfvzcJcjHpkIS/Qm1M=
This is decrypted text => Narendra
Output for 5.6.14
This is encrypted text of a string Narendra => CihVE6eKeQpYAmL+DsFq6coLuHBJxdpkyZgmxbQOujo=
This is decrypted text => Narendra
Output for 5.6.13
This is encrypted text of a string Narendra => 6tbUVkNzH2Qb5Re6KVDRs70IiUIGpjKkrtNxSPP786c=
This is decrypted text => Narendra
Output for 5.6.12
This is encrypted text of a string Narendra => yzIH0JkjDtL9H85Dek4VhNB5piSCFi2Aa5DcMzpjRZQ=
This is decrypted text => Narendra
Output for 5.6.11
This is encrypted text of a string Narendra => n7YBz5vhFr8XrsTqt7jKrZTnxmoAKVF49bL41wLb81A=
This is decrypted text => Narendra
Output for 5.6.10
This is encrypted text of a string Narendra => urBbolkm498GF4WMjsdfgnf4KBU5oo65MORIkeD8wKM=
This is decrypted text => Narendra
Output for 5.6.9
This is encrypted text of a string Narendra => d5YDGJECpouEdkSj+M/6fF5o6A0I62s9yeVG84QhIh8=
This is decrypted text => Narendra
Output for 5.6.8
This is encrypted text of a string Narendra => I4DqWX40tyMFKZ1j3xNYagTV4Djm39G5bskdgru8WAg=
This is decrypted text => Narendra
Output for 5.5.34
This is encrypted text of a string Narendra => QvlwBAvsHmO1cLdfNe51VSdHCxwAQ7IexU0j2m+l4WY=
This is decrypted text => Narendra
Output for 5.5.33
This is encrypted text of a string Narendra => krW4HBQW3z1yAC6s5p/LHyCRkYYFp54wZ9n1qEhhJDQ=
This is decrypted text => Narendra
Output for 5.5.32
This is encrypted text of a string Narendra => QjOZ6O2DAEOZKqViOemR7z3B08pIJ++oDj1+wNrPZoE=
This is decrypted text => Narendra
Output for 5.5.31
This is encrypted text of a string Narendra => EOLeOYglf2OegBp5LwTXA4qQujJSRN47mz2fEcaD/4Q=
This is decrypted text => Narendra
Output for 5.5.30
This is encrypted text of a string Narendra => wjAj7Cb+dwS/RFqWnzyV3v7T2Uk+U2/nB87v/aw7wO4=
This is decrypted text => Narendra
Output for 5.5.29
This is encrypted text of a string Narendra => UoOpr7Bldcchsy7kGbDZjl5IuFtmCR0z8nXKdJmkUmM=
This is decrypted text => Narendra
Output for 5.5.28
This is encrypted text of a string Narendra => kh6A67l1KjEKiB6y5urWHhzxXCimDV8BSl0CTgt0Zgk=
This is decrypted text => Narendra
Output for 5.5.27
This is encrypted text of a string Narendra => ElhAJCNwBpjoNZDCUJgEU76zwmzBAZrl4KmBxE+4LT0=
This is decrypted text => Narendra
Output for 5.5.26
This is encrypted text of a string Narendra => 2OPIndl/YRuN0+Pv7IE1n3vAn0dDN8AcUQUxlX4b4EA=
This is decrypted text => Narendra
Output for 5.5.25
This is encrypted text of a string Narendra => hI19axPzkq+Jcc8uEZ/dGWs3Q7z7Y6+eHymIs5P4QfM=
This is decrypted text => Narendra
Output for 5.5.24
This is encrypted text of a string Narendra => 7A0hBT9lxQIzZ/B1OpY6o2/vFWId4UjrbDyHB3VSnSw=
This is decrypted text => Narendra