mcrypt_cbc_3des_encrypt.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --TEST--
  2. Test mcrypt_cbc() function : basic functionality
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded("mcrypt")) {
  6. print "skip - mcrypt extension not loaded";
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
  12. * Description: CBC 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. echo "*** Testing mcrypt_cbc() : basic functionality ***\n";
  17. $cipher = MCRYPT_TRIPLEDES;
  18. $data = b"This is the secret message which must be encrypted";
  19. $mode = MCRYPT_ENCRYPT;
  20. // tripledes uses keys with exactly 192 bits (24 bytes)
  21. $keys = array(
  22. b'12345678',
  23. b'12345678901234567890',
  24. b'123456789012345678901234',
  25. b'12345678901234567890123456');
  26. // tripledes is a block cipher of 64 bits (8 bytes)
  27. $ivs = array(
  28. b'1234',
  29. b'12345678',
  30. b'123456789');
  31. $iv = b'12345678';
  32. echo "\n--- testing different key lengths\n";
  33. foreach ($keys as $key) {
  34. echo "\nkey length=".strlen($key)."\n";
  35. var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $iv)));
  36. }
  37. $key = b'123456789012345678901234';
  38. echo "\n--- testing different iv lengths\n";
  39. foreach ($ivs as $iv) {
  40. echo "\niv length=".strlen($iv)."\n";
  41. var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $iv)));
  42. }
  43. ?>
  44. ===DONE===
  45. --EXPECTF--
  46. *** Testing mcrypt_cbc() : basic functionality ***
  47. --- testing different key lengths
  48. key length=8
  49. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  50. Warning: mcrypt_cbc(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
  51. string(0) ""
  52. key length=20
  53. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  54. Warning: mcrypt_cbc(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
  55. string(0) ""
  56. key length=24
  57. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  58. string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
  59. key length=26
  60. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  61. Warning: mcrypt_cbc(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
  62. string(0) ""
  63. --- testing different iv lengths
  64. iv length=4
  65. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  66. Warning: mcrypt_cbc(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
  67. string(0) ""
  68. iv length=8
  69. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  70. string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
  71. iv length=9
  72. Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
  73. Warning: mcrypt_cbc(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
  74. string(0) ""
  75. ===DONE===