3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php const CIPHER = MCRYPT_RIJNDAEL_128; const KEY_BYTE_SIZE = 16; const CIPHER_MODE = 'cbc'; const HASH_FUNCTION = 'sha256'; const MAC_BYTE_SIZE = 32; const ENCRYPTION_INFO = 'PIPS|KeyForEncryption'; const AUTHENTICATION_INFO = 'PIPS|KeyForAuthentication'; $key = base64_decode('wdmd3XIhnOAelom4Y8yPbw=='); $ekey = HKDF(HASH_FUNCTION, $key, KEY_BYTE_SIZE, ENCRYPTION_INFO); //print "$ekey\n"; //print urlsafe_b64encode($ekey); $ivsize = mcrypt_get_iv_size(CIPHER, CIPHER_MODE); if ($ivsize === FALSE || $ivsize <= 0) { throw new CannotPerformOperationException(); } $iv = SecureRandom($ivsize); print urlsafe_b64encode($iv); function urlsafe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } function HKDF($hash, $ikm, $length, $info = '', $salt = NULL) { // Find the correct digest length as quickly as we can. $digest_length = MAC_BYTE_SIZE; if ($hash != HASH_FUNCTION) { $digest_length = strlen(hash_hmac($hash, '', '', true)); } // Sanity-check the desired output length. if (empty($length) || !is_int($length) || $length < 0 || $length > 255 * $digest_length) { return CannotPerformOperationException(); } // "if [salt] not provided, is set to a string of HashLen zeroes." if (is_null($salt)) { $salt = str_repeat("\x00", $digest_length); } // HKDF-Extract: // PRK = HMAC-Hash(salt, IKM) // The salt is the HMAC key. $prk = hash_hmac($hash, $ikm, $salt, true); // HKDF-Expand: // This check is useless, but it serves as a reminder to the spec. if (strlen($prk) < $digest_length) { throw new CannotPerformOperationException(); } // T(0) = '' $t = ''; $last_block = ''; for ($block_index = 1; strlen($t) < $length; $block_index++) { // T(i) = HMAC-Hash(PRK, T(i-1) | info | 0x??) $last_block = hash_hmac( $hash, $last_block . $info . chr($block_index), $prk, true ); // T = T(1) | T(2) | T(3) | ... | T(N) $t .= $last_block; } // ORM = first L octets of T $orm = substr($t, 0, $length); if ($orm === FALSE) { throw new CannotPerformOperationException(); } return $orm; } function SecureRandom($octets) { $random = mcrypt_create_iv($octets, MCRYPT_DEV_URANDOM); if ($random === FALSE) { throw new CannotPerformOperationException(); } else { return $random; } } ?>
based on V5QQB
Output for 7.2.0
Warning: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' (this will throw an Error in a future version of PHP) in /in/ebHon on line 3 Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/ebHon:16 Stack trace: #0 {main} thrown in /in/ebHon on line 16
Process exited with code 255.
Output for 7.0.6 - 7.1.10
Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /in/ebHon on line 3 Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/ebHon:16 Stack trace: #0 {main} thrown in /in/ebHon on line 16
Process exited with code 255.
Output for 7.0.5
VGWi7z6y-IEjMYZoQoRl4Q
Output for 7.0.4
2VCFj5-Oj_wSyH0ed4WiUw
Output for 7.0.3
ZHCmhmWVfy9ckSzMpRwdwg
Output for 7.0.2
4cZ8PkjhOdkeVch5PGpGcQ
Output for 7.0.1
pJ4n8X6NAXuIO_0tfrsRHQ
Output for 7.0.0
b6jGbRFtJ7gdYB70B8Z_Gw
Output for 5.3.19 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /in/ebHon on line 3 Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/ebHon on line 16
Process exited with code 255.
Output for 5.6.20
RW1tbIkTyhXb3eahlMu6xw
Output for 5.6.19
TRanGPCqVuWItv9YABzAyA
Output for 5.6.18
hL3fIvsWc-sNqBaxPQOWFw
Output for 5.6.17
5FuQHgKw0mg-52RkVcfHig
Output for 5.6.16
71n5xFbO_PUPJLFcZBEJBw
Output for 5.6.15
TBLg7wn0MXU4ZWOpp3bkTg
Output for 5.6.14
YSFCTBgzuw6AXV13xz216A
Output for 5.6.13
TDkfqnjs9JhSySlKVpfBzA
Output for 5.6.12
XMvAi1w15kuS8i2pbwGhLA
Output for 5.6.11
5bigQ-6pwXu59_X0tlC-1A
Output for 5.6.10
naT2xVIBR5a6kHTcVnDnzg
Output for 5.6.9
aIdkabqvUASq8Vr-empZJA
Output for 5.6.8
uE8po6xMLcqef4mtCjMpBw
Output for 5.5.34
w3dwrLracou2HLS8tmKseg
Output for 5.5.33
yw3XmJR6RcEv4kH4TtEPZA
Output for 5.5.32
ETKpGCLvxvfVjERKoaNSPA
Output for 5.5.31
LmYQjDpamleU2zgKncpRbw
Output for 5.5.30
68-Q5O3uKmRRt_fHT0O47Q
Output for 5.5.29
TYh6NzwKZ5EwBjbcBRUEwg
Output for 5.5.28
_ChaPGzxKgV-xjf-TEVsoA
Output for 5.5.27
biVKHhLVIUqzBABD75DGxA
Output for 5.5.26
Nbe_hcWrL3aC6SEkxYujGw
Output for 5.5.25
R0sISPGF9BqY-PqY3OmMdA
Output for 5.5.24
YYullw_uRxuSoPuUinjq_g
Output for 5.4.45
3KsDPg_lmOC8F-dtD3HTJA
Output for 5.4.44
yC_ok2BUkLNxhcCJvy1BrA
Output for 5.4.43
KCIiEonXHlSSo92oBn0_rw
Output for 5.4.42
7U7YHN2UHLNeHv6lXsAPZQ
Output for 5.4.41
4qmIx6hompU7Vg5OOdKWog
Output for 5.4.40
77ohdyr-p4qsy0tGa1Gi6A
Output for 5.4.39
8EpgxRNVrO7gILqsIpEvyg
Output for 5.4.38
9wTtO_JYATxte1f2hSBP8A
Output for 5.4.37
5iXADbG-yQ9JqYhm03Cf4Q
Output for 5.4.36
38o1uR4tX38jBF6Xvo4Pww
Output for 5.4.35
9E1pZcs0DR5haxenU9Rb0w
Output for 5.4.34
Donoy5UAODtVKalDb0FttA
Output for 5.4.32
obsfuRBVkhVaXMAOdEnKyQ
Output for 5.4.31
WAIFtuKm3tHYsMD1BrMgyA
Output for 5.4.30
QbYKxqs2F6iv82a4gpYvcA
Output for 5.4.29
fDEe9kg2CqL-UQv9uuoMUA
Output for 5.4.28
17a81vsWGd1zNxvx-jkydQ
Output for 5.4.27
TNac5r-rZeqRuFuYUCG98Q
Output for 5.4.26
6sXngnACk_qOCePZa6k97Q
Output for 5.4.25
hAfKBQ-HV2dGnYEqt4xLAw
Output for 5.4.24
6fxH_XQJP-TAXRhqqnxHWg
Output for 5.4.23
TcWdL3GsSmD7vgHCFBb5lw
Output for 5.4.22
6f3qqdCDstANM15zzc1EMw
Output for 5.4.21
at2bUHZX-kmKaMcT3H1RaA
Output for 5.4.20
VX6xo7jU7mGYcRhbtnw0RQ
Output for 5.4.19
kCHuxsl3pMElTqFXf1Kdqg
Output for 5.4.18
WXbwmfyIrpV_Z9nulalzLA
Output for 5.4.17
fE_pxmSsrOC_bcxv9q3o-g
Output for 5.4.16
fplNblG2hqybSaLNAMHijw
Output for 5.4.15
oXc4pMoXZXM2WGjBzO_Bkw
Output for 5.4.14
QErjUm8dugSzbrsZu4xfXw
Output for 5.4.13
xKFStC0fBTWKVMBKpqGrOQ
Output for 5.4.12
KOOvLIDESFKOLkGHx2Caog
Output for 5.4.11
VByC5s6QG2jjYZpNUbufGg
Output for 5.4.10
JKHZviWze73HHQ3TmEitZg
Output for 5.4.9
WSD_JJKjoDNF59674nrucQ
Output for 5.4.8
cvezihZbsQSfB6NbQRBfLA
Output for 5.4.7
U1Y7ndDaiXhiAUswgu-Qjw
Output for 5.4.6
LTdFKdcYPHSbuYr7zW34rg
Output for 5.4.5
lYVNZZElsRdaaSrRtMDhHQ
Output for 5.4.4
fq5jZYQZgWR5xlYZkRSagQ
Output for 5.4.3
5mfvfwDPUe1tLzpJyrEzPA
Output for 5.4.2
yOnjZQ7Na30JdhFPNEBp-g
Output for 5.4.1
L0Opk0RRimCKfENKAhqm0Q
Output for 5.4.0
mOgukMJabE5z7qMo4tmx1Q