@ 2016-04-18T16:45:19Z <?php
class AESEncryptExampleClass {
public function _encrypt($plaintext, $passphrase, $keySize, $salt, $iv, $iterationCount) {
$mode = MCRYPT_MODE_CBC;
//Generate AES encryption key
$key = $this->_pbkdf2($passphrase, $salt, $iterationCount, $this->_parseKeyInt(MCRYPT_RIJNDAEL_128));
echo base64_encode($key) . "\n";
try {
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->_pkcs5Pad($plaintext), $mode, $iv);
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
return (base64_encode($ciphertext));
}
public function _getRandomBytes($length = 8) {
$characters = '0123456789';
$charactersLength = strlen($characters) - 1;
$bytes = '';
//Select some random characters
for ($i = 0; $i < $length; $i++) {
$bytes .= $characters[mt_rand(0, $charactersLength)];
}
return $bytes;
}
private function _pbkdf2($passphrase, $salt, $iterationCount = 1000, $keyLength = MCRYPT_RIJNDAEL_128, $algorithm = 'sha1') {
$hashLength = strlen( hash( $algorithm, null, true ) );
$blockCount = ceil( $keyLength / $hashLength );
$output = '';
//Create key
for ( $block = 1; $block <= $blockCount; $block++ ) {
//Initial hash for this block
$xorsum = $last = hash_hmac( $algorithm, $salt . pack( 'N', $block ), $passphrase, true );
//Perform block iterations
for ( $i = 1; $i < $iterationCount; $i++ ) {
//XOR each iterate
$xorsum ^= ( $last = hash_hmac( $algorithm, $last, $passphrase, true ) );
}
//Append iterated block
$output .= $xorsum;
}
//Return derived key of correct length
return substr( $output, 0, $keyLength );
}
private function _parseKeyInt($keySize) {
$key = "";
if ($keySize == MCRYPT_RIJNDAEL_128) {
$key = 16;
}
else if ($keySize == MCRYPT_RIJNDAEL_192) {
$key = 24;
}
else if ($keySize == MCRYPT_RIJNDAEL_256) {
$key = 32;
}
return $key;
}
private function _pkcs5Pad($text) {
$blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$padding = $blockSize - (strlen($text) % $blockSize);
$text .= str_repeat(chr($padding), $padding);
return $text;
}
}
/*-----------------------------------------------------------*
* EXAMPLE USING AESEncryptExampleClass *
*-----------------------------------------------------------*/
$iterationCount = 1000;
$keySize = 128;
$youmapsKey = "YOUR_YOUMAPS_KEY";
$url = "exampleURL";
//Initialize AESEncryptExampleClass
$aesEncrypt = new AESEncryptExampleClass();
//Generate random IV and salt
$salt = "12é4567891234567";
$iv = "1234567891234567";
//$salt = $aesEncrypt->_getRandomBytes(16);
//$iv = $aesEncrypt->_getRandomBytes(16);
//Encrypt the URL
$encryptedURL = $aesEncrypt->_encrypt($url, $youmapsKey, $keySize, $salt, $iv, $iterationCount);
echo $encryptedURL;
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.2.0 0.006 0.006 19.65 7.1.7 0.009 0.003 17.21 7.1.6 0.004 0.018 19.25 7.1.5 0.006 0.006 16.77 7.1.0 0.003 0.080 22.57 7.0.20 0.006 0.006 16.86 7.0.6 0.020 0.057 21.63 7.0.5 0.010 0.083 20.38 7.0.4 0.027 0.070 20.30 7.0.3 0.010 0.073 20.33 7.0.2 0.017 0.063 20.45 7.0.1 0.027 0.070 20.36 7.0.0 0.017 0.057 20.27 5.6.28 0.007 0.073 21.14 5.6.21 0.010 0.067 20.71 5.6.20 0.033 0.080 21.15 5.6.19 0.053 0.057 21.18 5.6.18 0.033 0.067 21.11 5.6.17 0.007 0.077 21.14 5.6.16 0.023 0.063 21.11 5.6.15 0.030 0.053 21.16 5.6.14 0.033 0.067 21.01 5.6.13 0.033 0.083 21.13 5.6.12 0.013 0.070 21.14 5.6.11 0.037 0.060 21.09 5.6.10 0.020 0.073 21.13 5.6.9 0.023 0.067 21.25 5.6.8 0.027 0.050 20.48 5.6.7 0.023 0.080 20.49 5.6.6 0.030 0.053 20.49 5.6.5 0.000 0.073 20.39 5.6.4 0.020 0.060 20.50 5.6.3 0.023 0.053 20.66 5.6.2 0.023 0.063 20.54 5.6.1 0.017 0.063 20.49 5.6.0 0.020 0.057 20.47 5.5.35 0.420 0.047 20.32 5.5.34 0.020 0.057 20.93 5.5.33 0.030 0.093 20.94 5.5.32 0.040 0.050 20.96 5.5.31 0.017 0.080 21.01 5.5.30 0.040 0.073 20.93 5.5.29 0.037 0.067 21.01 5.5.28 0.007 0.067 20.96 5.5.27 0.023 0.090 20.89 5.5.26 0.027 0.060 20.89 5.5.25 0.027 0.050 20.74 5.5.24 0.030 0.053 20.51 5.5.23 0.027 0.053 20.17 5.5.22 0.027 0.050 20.44 5.5.21 0.023 0.057 20.27 5.5.20 0.027 0.050 20.36 5.5.19 0.023 0.060 20.11 5.5.18 0.013 0.070 20.27 5.5.16 0.020 0.070 20.24 5.5.15 0.017 0.067 20.28 5.5.14 0.013 0.057 20.47 5.5.13 0.037 0.070 20.35 5.5.12 0.040 0.053 20.27 5.5.11 0.043 0.073 20.45 5.5.10 0.043 0.077 20.38 5.5.9 0.023 0.063 20.16 5.5.8 0.023 0.067 20.34 5.5.7 0.023 0.060 20.25 5.5.6 0.013 0.060 20.33 5.5.5 0.017 0.057 20.33 5.5.4 0.033 0.060 20.25 5.5.3 0.037 0.053 20.18 5.5.2 0.027 0.053 20.08 5.5.1 0.007 0.083 20.24 5.5.0 0.020 0.050 20.16
preferences:dark mode live preview
54.81 ms | 400 KiB | 5 Q