Encryption.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Config;
  3. use CodeIgniter\Config\BaseConfig;
  4. /**
  5. * Encryption configuration.
  6. *
  7. * These are the settings used for encryption, if you don't pass a parameter
  8. * array to the encrypter for creation/initialization.
  9. */
  10. class Encryption extends BaseConfig
  11. {
  12. /**
  13. * --------------------------------------------------------------------------
  14. * Encryption Key Starter
  15. * --------------------------------------------------------------------------
  16. *
  17. * If you use the Encryption class you must set an encryption key (seed).
  18. * You need to ensure it is long enough for the cipher and mode you plan to use.
  19. * See the user guide for more info.
  20. */
  21. public string $key = '';
  22. /**
  23. * --------------------------------------------------------------------------
  24. * Previous Encryption Keys
  25. * --------------------------------------------------------------------------
  26. *
  27. * When rotating encryption keys, add old keys here to maintain ability
  28. * to decrypt data encrypted with previous keys. Encryption always uses
  29. * the current $key. Decryption tries current key first, then falls back
  30. * to previous keys if decryption fails.
  31. *
  32. * In .env file, use comma-separated string:
  33. * encryption.previousKeys = hex2bin:9be8c64fcea509867...,hex2bin:3f5a1d8e9c2b7a4f6...
  34. *
  35. * @var list<string>|string
  36. */
  37. public array|string $previousKeys = '';
  38. /**
  39. * --------------------------------------------------------------------------
  40. * Encryption Driver to Use
  41. * --------------------------------------------------------------------------
  42. *
  43. * One of the supported encryption drivers.
  44. *
  45. * Available drivers:
  46. * - OpenSSL
  47. * - Sodium
  48. */
  49. public string $driver = 'OpenSSL';
  50. /**
  51. * --------------------------------------------------------------------------
  52. * SodiumHandler's Padding Length in Bytes
  53. * --------------------------------------------------------------------------
  54. *
  55. * This is the number of bytes that will be padded to the plaintext message
  56. * before it is encrypted. This value should be greater than zero.
  57. *
  58. * See the user guide for more information on padding.
  59. */
  60. public int $blockSize = 16;
  61. /**
  62. * --------------------------------------------------------------------------
  63. * Encryption digest
  64. * --------------------------------------------------------------------------
  65. *
  66. * HMAC digest to use, e.g. 'SHA512' or 'SHA256'. Default value is 'SHA512'.
  67. */
  68. public string $digest = 'SHA512';
  69. /**
  70. * Whether the cipher-text should be raw. If set to false, then it will be base64 encoded.
  71. * This setting is only used by OpenSSLHandler.
  72. *
  73. * Set to false for CI3 Encryption compatibility.
  74. */
  75. public bool $rawData = true;
  76. /**
  77. * Encryption key info.
  78. * This setting is only used by OpenSSLHandler.
  79. *
  80. * Set to 'encryption' for CI3 Encryption compatibility.
  81. */
  82. public string $encryptKeyInfo = '';
  83. /**
  84. * Authentication key info.
  85. * This setting is only used by OpenSSLHandler.
  86. *
  87. * Set to 'authentication' for CI3 Encryption compatibility.
  88. */
  89. public string $authKeyInfo = '';
  90. /**
  91. * Cipher to use.
  92. * This setting is only used by OpenSSLHandler.
  93. *
  94. * Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
  95. * by CI3 Encryption default configuration.
  96. */
  97. public string $cipher = 'AES-256-CTR';
  98. }