3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. class Cryptor { protected $method = 'AES-128-CTR'; // default private $key; protected function iv_bytes() { return openssl_cipher_iv_length($this->method); } public function __construct($key = FALSE, $method = FALSE) { if(!$key) { // if you don't supply your own key, this will be the default $key = gethostname() . "|" . ip2long($_SERVER['SERVER_ADDR']); } if(ctype_print($key)) { // convert key to binary format $this->key = openssl_digest($key, 'SHA256', TRUE); } else { $this->key = $key; } if($method) { if(in_array($method, openssl_get_cipher_methods())) { $this->method = $method; } else { die(__METHOD__ . ": unrecognised encryption method: {$method}"); } } } public function encrypt($data) { $iv = openssl_random_pseudo_bytes($this->iv_bytes()); $encrypted_string = bin2hex($iv) . openssl_encrypt($data, $this->method, $this->key, 0, $iv); return $encrypted_string; } // decrypt encrypted string public function decrypt($data) { $iv_strlen = 2 * $this->iv_bytes(); if(preg_match("/^(.{" . $iv_strlen . "})(.+)$/", $data, $regs)) { list(, $iv, $crypted_string) = $regs; $decrypted_string = openssl_decrypt($crypted_string, $this->method, $this->key, 0, hex2bin($iv)); return $decrypted_string; } else { return FALSE; } } } $token = "The quick brown fox jumps over the lazy dog."; $encryption_key = 'CKXH2U9RPY3EFD70TLS1ZG4N8WQBOVI6AMJ5'; $cryptor = new Cryptor($encryption_key); $crypted_token = $cryptor->encrypt($token); unset($token); echo $crypted_token;
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function openssl_digest() in /in/J0Wgs:25 Stack trace: #0 /in/J0Wgs(63): Cryptor->__construct('CKXH2U9RPY3EFD7...') #1 {main} thrown in /in/J0Wgs on line 25
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.44 ms | 401 KiB | 8 Q