Skip to content

hook_civicrm_crypto

Summary

This hook was added in 5.33 and allows for extension authors to define more keys and ciphers that are then used in the Crypto Registry.

Definition

hook_civicrm_crypto($registry)

Parameters

  • $registry (@param \Civi\Crypto\CryptoRegistry) - The CryptoRegistry tracks a list of keys and ciphers.

Returns

  • null - the return value is ignored

Example

Add a new key

  function civitest_civicrm_crypto($registry) {
    $registry->addSymmetricKey([
      'key' => hash_hkdf('sha256', 'abcd1234'),
      'suite' => 'aes-cbc-hs',
    ]);
  }

Add new keys and tag them for use in some encryption-decryption process

  // Register some keys. Tag them as 'SESSION'.
  function civitest_civicrm_crypto($registry) {
    $registry->addSymmetricKey([
      'key' => '12345678901234567890123456789012',
      'suite' => 'aes-cbc-hs',
      'tags' => ['SESSION'],
      'weight' => -1, // Preferred for new encrypting new values
    ]);
    $registry->addSymmetricKey([
      'key' => 'abcdefghijklmnopqrstuvwxyz123456',
      'suite' => 'aes-cbc-hs',
      'tags' => ['SESSION'],
      'weight' => 10, // Available for decrypting old values
    ]);
  }