I'm trying to load in a composer package: archwisp/php-encrypt-data, and while I'm able to use it in a test php script, using it in Drupal itself doesn't seem to be working.

This is the test script:

require __DIR__ . '/vendor/autoload.php';

$encryptionKey = 'IyJQdVtyNClqQ+ybuxHWNhJnw93ocxJuLruRztQPNI0=';
$macKey = 'pbJqXp4YhhtRYv/Ntt/i+O4KbO1F4/2bktO08m0+Exo=';

$phpcrypt = new \PHPEncryptData\Simple($encryptionKey, $macKey);

$ciphertext = $phpcrypt->encrypt('Foobar');

echo $ciphertext . "\n";

echo $phpcrypt->decrypt($ciphertext) . "\n";

But, I don't understand what I have to do in a Drupal class to make this work. I tried to use archwisp\PHPEncryptData; at the top of the file, and I tried doing require DRUPAL_ROOT . '/vendor/autoload.php'; as well, but no matter what, it always says: Call to undefined function PHPEncryptData\\mcrypt_get_key_size()

Is it because it didn't do the autoload the same way, or is it getting mixed up because of namespaces? The error is coming from the composer package itself, so it is locating that, but for some reason it's not calling the mcrypt function correctly, even though the extension is enabled and working in the test script.

  • Is this Drupal 7 or 8? – Kevin Oct 5 '16 at 21:41
  • It's kind of hard to notice, but I tagged it with the [8] tag at the bottom. – RaisinBranCrunch Oct 5 '16 at 21:57

Call to undefined function PHPEncryptData\mcrypt_get_key_size()

mcrypt is a php function of the mcrypt extension. Autloading is working perfectly fine, or you wouldn't get that far. You're simply missing that extension.

The error message is a bit confusing because PHP always looks for functions in the global namespace and in the namespace the code is in and then prints the error for the one with the namespace.

|improve this answer|||||
  • I am 100% sure I had the extension. But, it is working now. Is it possible the absence of the extension was being cached by APC or something? – RaisinBranCrunch Oct 7 '16 at 20:04
  • Nope. but maybe you hadn't restarted apache after enabling the extension or something like that. – Berdir Oct 7 '16 at 20:23

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.