0

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?

0

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 :)
0

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

Ex:

<p>a:6:{s:4:"text";s:128:"Kuh1EzLdKbebW7WI7mPLKo/g2HEA4R3c+Y3b+IKF0MGH3Oa8Bc7x5Gh+u+9wmc8EKGyc4Gdudwtvb3n6EjXNL6cIrr6EZDSsHFafspObcxYpNJhQBKGAf6134PiC4jqv";s:6:"method";s:14:"mcrypt_aes_cbc";s:12:"key_provider";s:4:"file";s:7:"options";a:0:{}s:15:"method_settings";s:0:"";s:17:"provider_settings";a:2:{s:4:"path";s:19:"sites/default/files";s:6:"method";s:13:"base64_decode";}}</p>

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.