I am using the Encrypt module to encrypt some of user object data.

I can encrypt data, but while decrypt it, I get the following error:

Decryption failed because the HMAC could not be validated

encrypt('name') // It works.
decrypt('some encrypted data') // It throws the above error.

How can I decrypt data using that module?


I have found below solution. I have un-serialized encrypted data. Found below details.

enter image description here

Used above input to decrypt function.

$options = array();
$method = 'mcrypt_aes_cbc';
$key_provider = 'drupal_variable';
$config = array('provider_settings' => array('method' => 'variable_contents')); // I have updated method name later.
decrypt('encrypted_text', $options, $method, $key_provider, $config); // It works now :)

For me turns out that the value of the body that was being retrieved had <p> tags around it.



so all I had to do was strip those tags.

  $body = $vars['message_body'];
  $body = strip_tags($body);
  $vars['message_body'] = decrypt($body);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.