1--TEST-- 2Test mcrypt_encrypt() function : AES functionality 3--SKIPIF-- 4<?php 5if (!extension_loaded("mcrypt")) { 6 print "skip - mcrypt extension not loaded"; 7} 8?> 9--FILE-- 10<?php 11/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv) 12 * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv 13 * Source code: ext/mcrypt/mcrypt.c 14 * Alias to functions: 15 */ 16 /* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv) 17 * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv 18 * Source code: ext/mcrypt/mcrypt.c 19 * Alias to functions: 20 */ 21 /* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv) 22 * Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv 23 * Source code: ext/mcrypt/mcrypt.c 24 * Alias to functions: 25 */ 26 27echo "*** Testing mcrypt : Rijndael128 functionality ***\n"; 28 29$cipher = MCRYPT_RIJNDAEL_128; 30$mode = MCRYPT_MODE_CBC; 31$data = b'This is the secret message which must be encrypted'; 32 33// keys up to 128 bits (16 bytes) 34$keys = array( 35 null, 36 '', 37 b'12345678', 38 b'1234567890123456' 39); 40// rijndael128 is a block cipher of 128 bits (16 bytes) 41$ivs = array( 42 null, 43 '', 44 b'12345678', 45 b'1234567890123456', 46 b'12345678901234567' 47); 48 49 50$iv = b'1234567890123456'; 51echo "\n--- testing different key lengths\n"; 52foreach ($keys as $key) { 53 echo "\nkey length=".strlen($key)."\n"; 54 $res = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_CBC, $iv); 55 var_dump(bin2hex($res)); 56} 57 58$key = b'1234567890123456'; 59echo "\n--- testing different iv lengths\n"; 60foreach ($ivs as $iv) { 61 echo "\niv length=".strlen($iv)."\n"; 62 $res = mcrypt_decrypt($cipher, $key, $res, MCRYPT_MODE_CBC, $iv); 63 var_dump(bin2hex($res)); 64} 65 66?> 67===DONE=== 68--EXPECTF-- 69*** Testing mcrypt : Rijndael128 functionality *** 70 71--- testing different key lengths 72 73key length=0 74 75Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 45 76 77Warning: mcrypt_encrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 78string(0) "" 79 80key length=0 81 82Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 45 83 84Warning: mcrypt_encrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 85string(0) "" 86 87key length=8 88 89Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 45 90 91Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 92string(0) "" 93 94key length=16 95 96Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 45 97string(128) "dc8f957ec530acf10cd95ba7da7b6405380fe19a2941e9a8de54680512f18491bc374e5464885ae6c2ae2aa7a6cdd2fbe12a06bbc4bd59dbbfaa15f09044f101" 98 99--- testing different iv lengths 100 101iv length=0 102 103Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 53 104 105Warning: mcrypt_decrypt(): Received initialization vector of size 0, but size 16 is required for this encryption mode in %s on line %d 106string(0) "" 107 108iv length=0 109 110Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 53 111 112Warning: mcrypt_decrypt(): Received initialization vector of size 0, but size 16 is required for this encryption mode in %s on line %d 113string(0) "" 114 115iv length=8 116 117Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 53 118 119Warning: mcrypt_decrypt(): Received initialization vector of size 8, but size 16 is required for this encryption mode in %s on line %d 120string(0) "" 121 122iv length=16 123 124Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 53 125string(32) "42adc8c0db19473f2c684ff2d6e828a5" 126 127iv length=17 128 129Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line 53 130 131Warning: mcrypt_decrypt(): Received initialization vector of size 17, but size 16 is required for this encryption mode in %s on line %d 132string(0) "" 133===DONE=== 134