original_string: public function set_value($value) {
  
          // No openssl available, skip this field completely.
          if (!function_exists('openssl_encrypt')) {
              return;
          }
  
          // No hmac available, skip this field completely.
          if (!function_exists('hash_hmac')) {
              return;
          }
  
          // Cypher not available, skip this field completely.
          if (!in_array(backup::CIPHER, openssl_get_cipher_methods())) {
              return;
          }
  
          // Ensure we have a good key, manual or default.
          if (empty($this->key)) {
              // The key has not been set manually, look for it at config (base64 encoded there).
              $enckey = get_config('backup', 'backup_encryptkey');
              if ($enckey === false) {
                  // Has not been set, calculate and save an appropiate random key automatically.
                  $enckey = base64_encode(self::generate_encryption_random_key(backup::CIPHERKEYLEN));
                  set_config('backup_encryptkey', $enckey, 'backup');
              }
              $this->set_key(base64_decode($enckey));
          }
  
          // Now we need an iv for this operation.
          $iv = self::generate_encryption_random_key(openssl_cipher_iv_length(backup::CIPHER));
  
          // Everything is ready, let's encrypt and prepend the 1-shot iv.
          $value = $iv . openssl_encrypt($value, backup::CIPHER, $this->key, OPENSSL_RAW_DATA, $iv);
  
          // Calculate the hmac of the value (iv + encrypted) and prepend it.
          $hmac = hash_hmac('sha256', $value, $this->key, true);
          $value = $hmac . $value;
  
          // Ready, set the encoded value.
          parent::set_value(base64_encode($value));
  
          // Finally, if the field has an "encrypted" attribute, set it to true.
          if ($att = $this->get_attribute('encrypted')) {
              $att->set_value('true');
          }
      }
code: public function set_value($value) {
  
          // No openssl available, skip this field completely.
          if (!function_exists('openssl_encrypt')) {
              return;
          }
  
          // No hmac available, skip this field completely.
          if (!function_exists('hash_hmac')) {
              return;
          }
  
          // Cypher not available, skip this field completely.
          if (!in_array(backup::CIPHER, openssl_get_cipher_methods())) {
              return;
          }
  
          // Ensure we have a good key, manual or default.
          if (empty($this->key)) {
              // The key has not been set manually, look for it at config (base64 encoded there).
              $enckey = get_config('backup', 'backup_encryptkey');
              if ($enckey === false) {
                  // Has not been set, calculate and save an appropiate random key automatically.
                  $enckey = base64_encode(self::generate_encryption_random_key(backup::CIPHERKEYLEN));
                  set_config('backup_encryptkey', $enckey, 'backup');
              }
              $this->set_key(base64_decode($enckey));
          }
  
          // Now we need an iv for this operation.
          $iv = self::generate_encryption_random_key(openssl_cipher_iv_length(backup::CIPHER));
  
          // Everything is ready, let's encrypt and prepend the 1-shot iv.
          $value = $iv . openssl_encrypt($value, backup::CIPHER, $this->key, OPENSSL_RAW_DATA, $iv);
  
          // Calculate the hmac of the value (iv + encrypted) and prepend it.
          $hmac = hash_hmac('sha256', $value, $this->key, true);
          $value = $hmac . $value;
  
          // Ready, set the encoded value.
          parent::set_value(base64_encode($value));
  
          // Finally, if the field has an "encrypted" attribute, set it to true.
          if ($att = $this->get_attribute('encrypted')) {
              $att->set_value('true');
          }
      }
code_tokens: public function set_value ( $ value ) { // No openssl available, skip this field completely. if ( ! function_exists ( 'openssl_encrypt' ) ) { return ; } // No hmac available, skip this field completely. if ( ! function_exists ( 'hash_hmac' ) ) { return ; } // Cypher not available, skip this field completely. if ( ! in_array ( backup :: CIPHER , openssl_get_cipher_methods ( ) ) ) { return ; } // Ensure we have a good key, manual or default. if ( empty ( $ this -> key ) ) { // The key has not been set manually, look for it at config (base64 encoded there). $ enckey = get_config ( 'backup' , 'backup_encryptkey' ) ; if ( $ enckey === false ) { // Has not been set, calculate and save an appropiate random key automatically. $ enckey = base64_encode ( self :: generate_encryption_random_key ( backup :: CIPHERKEYLEN ) ) ; set_config ( 'backup_encryptkey' , $ enckey , 'backup' ) ; } $ this -> set_key ( base64_decode ( $ enckey ) ) ; } // Now we need an iv for this operation. $ iv = self :: generate_encryption_random_key ( openssl_cipher_iv_length ( backup :: CIPHER ) ) ; // Everything is ready, let's encrypt and prepend the 1-shot iv. $ value = $ iv . openssl_encrypt ( $ value , backup :: CIPHER , $ this -> key , OPENSSL_RAW_DATA , $ iv ) ; // Calculate the hmac of the value (iv + encrypted) and prepend it. $ hmac = hash_hmac ( 'sha256' , $ value , $ this -> key , true ) ; $ value = $ hmac . $ value ; // Ready, set the encoded value. parent :: set_value ( base64_encode ( $ value ) ) ; // Finally, if the field has an "encrypted" attribute, set it to true. if ( $ att = $ this -> get_attribute ( 'encrypted' ) ) { $ att -> set_value ( 'true' ) ; } }
docstring: Set the value of the field.
  
  This method sets the value of the element, encrypted using the specified key for it,
  defaulting to (and generating) backup_encryptkey config. HMAC is used for integrity.
  
  @param string $value plain-text content the will be stored encrypted and encoded.
docstring_tokens: Set the value of the field .