2

Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred. Cannot decrypt token. Invalid format. Return to home page.

I have installed the SparkPost extension for CiviCRM 5.39.0 on Drupal 7.82. I have ensured that the installation steps 1, 2 and 3 here are complete. When attempting to follow step four, going to Administer > System Settings > Outgoing mail (SparkPost) I receive the above error on the screen.

I have cleared caches and double-checked paths.

Google search shows exactly one post with this verbiage but I am not able to figure out the relationship between that one issue and this: https://lab.civicrm.org/dev/core/-/issues/2563. It only comes up here as part of the exceptions thrown verbiage in the codebase.

Note: I am working on getting CiviCRM updated, but since CiviSMTP is kaput by Aug 1, 2022, I was hoping that updating CiviCRM was not the solution.

Please let me know what else I can try, thank you!

    Jul 31 22:09:44  [error] 
$Fatal Error Details = array:3 [
  "message" => "Cannot decrypt token. Invalid format."
  "code" => null
  "exception" => Civi\Crypto\Exception\CryptoException {#1368
    -errorData: array:1 [
      "error_code" => 0
    ]
    #cause: null
    -_trace: null
    #message: "Cannot decrypt token. Invalid format."
    #code: 0
    #file: "/var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/Civi/Crypto/CryptoToken.php"
    #line: 206
    trace: {
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/Civi/Crypto/CryptoToken.php:206 {
        ›   default:
        ›     throw new CryptoException("Cannot decrypt token. Invalid format.");
        › }
      }
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/Civi/Crypto/CryptoToken.php:141 { …}
      /var/www/html/fosterclub/docroot/sites/default/files/civicrm/ext/com.cividesk.email.sparkpost/CRM/Sparkpost.php:54 { …}
      /var/www/html/fosterclub/docroot/sites/default/files/civicrm/ext/com.cividesk.email.sparkpost/CRM/Admin/Form/Setting/Sparkpost.php:64 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Core/Form.php:644 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Core/QuickForm/Action/Display.php:76 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/packages/HTML/QuickForm/Controller.php:203 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/packages/HTML/QuickForm/Page.php:103 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Core/Controller.php:352 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Utils/Wrapper.php:98 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Core/Invoke.php:286 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Core/Invoke.php:69 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/CRM/Core/Invoke.php:36 { …}
      /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/drupal/civicrm.module:458 { …}
      /var/www/html/fosterclub/docroot/includes/menu.inc:527 { …}
      /var/www/html/fosterclub/docroot/index.php:21 { …}
    }
  }
]
7
  • I found this reported issue, which may be the same: lab.civicrm.org/extensions/sparkpost/-/issues/110
    – Christia
    Aug 2, 2022 at 1:28
  • I'm having the same issue as the OP, and tried the answer below and it didn't work.
    – Zachary
    Aug 3, 2022 at 20:27
  • 1
    This may not be helpful, other than offering hope, but we needed to switch client to SparkPost. D7, civi 5.49.x, SparkPost 1.5. We succeeded with no problems relating to tokens. If i can help in anyway then happy to try.
    – petednz - fuzion
    Aug 3, 2022 at 22:54
  • 1
    wild guess but might php version be a possible factor
    – petednz - fuzion
    Aug 3, 2022 at 22:58
  • I am using PHP 7.2 but will consider going to 7.3 or 7.4 if that helps. I ended up implementing SendGrid because the prices are similar enough and it worked out of the box, so I will likely not switch back unless some other reasoning comes up.
    – Zachary
    Aug 3, 2022 at 23:32

3 Answers 3

2

Install from git. The sparkpost-1.5.tar.gz was released after fixes for this were committed in July, but for some reason aren't in the release.

1

It might also be that your crypto keys in civicrm.settings.php aren't using a valid format. The docs are a bit difficult to follow to figure out how to generate a proper key. You can use this tool: https://civisettings.symbiotic.coop

Note you need to REPLACE the existing lines for CRED_KEYS and SIGN_KEYS in civicrm.settings.php with the output, not add more lines to the file at the end, since then the existing lines will still get used.

You may also need to clear out any existing api key and re-enter it on the admin page to get it re-encrypted. You can delete it in mysql directly with delete from civicrm_setting where name='sparkpost_apiKey';

Also make sure you are using the latest version of sparkpost - note there were some changes added last week related to crypto.

6
  • I updated the file with the code in the tool, was that what I was supposed to do? It didn't fix the issue, after also rebuilding caches and permissions, etc.
    – Christia
    Aug 3, 2022 at 20:54
  • I have tried adding these settings to my civicrm.settings.php file and it has not resolved the above issue.
    – Zachary
    Aug 3, 2022 at 21:15
  • 1
    Ok it's possible there's an issue in the extension, but I'll update the answer with a couple more things.
    – Demerit
    Aug 5, 2022 at 12:04
  • Tried this and it didn't work.
    – Shai
    Aug 9, 2022 at 21:06
  • a few comments. our first sparkpost set up went fine. our second one hit this token issue. i wondered if we had done something different, eg using cv en on the latter but not on the first, since i noticed that the row in civicrm_settings had no 'created id'. so i disabled via cv. then enabled via UI. no difference. I then uninstalled via UI at which point the com.cividesk.email.sparkpost:version row in db still existed, but now had a created_id of my contact. i triend enabling via UI again. same issue
    – petednz - fuzion
    Aug 23, 2022 at 5:39
0

Seems the fix for this is in git, but is not in the zip even though v1.5 was tagged after fixes were applied for some reason isn't in the sparkpost-1.5.tar.gz

Suggest "git clone [email protected]:extensions/sparkpost.git". Then delete the .git folder in the sparkpost extension directory as you probably don't want to keep that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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