Answers.Body: <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-23T13:27:28.133Z
Answers.LastActivityDate: 2022-08-23T13:27:28.133Z
Answers.UserDisplayName: konadave
Answers.Body: <p>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: <a href="https://civisettings.symbiotic.coop" rel="nofollow noreferrer">https://civisettings.symbiotic.coop</a></p>
  <p>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.</p>
  <p>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 <code>delete from civicrm_setting where name='sparkpost_apiKey';</code></p>
  <p>Also make sure you are using the latest version of sparkpost - note there were some changes added last week related to crypto.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-03T20:54:05.070Z
Answers.Text: 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.
Answers.UserDisplayName: Christia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-03T21:15:16.807Z
Answers.Text: I have tried adding these settings to my civicrm.settings.php file and it has not resolved the above issue.
Answers.UserDisplayName: Zachary
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-05T12:04:53.923Z
Answers.Text: Ok it's possible there's an issue in the extension, but I'll update the answer with a couple more things.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-09T21:06:18.750Z
Answers.Text: Tried this and it didn't work.
Answers.UserDisplayName: Shai
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-23T05:39:26.970Z
Answers.Text: 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
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-23T05:40:45.103Z
Answers.Text: i then tried editing the civicrm.settings.php - no improvement. i await my technical colleague joining in this hunt tomorrow. Note, this is a much older site. is on same civi version now, but has been around for > 10 years (just in case that is part of the puzzle)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-02T14:02:41.680Z
Answers.LastActivityDate: 2022-08-05T12:12:34.483Z
Answers.LastEditDate: 2022-08-05T12:12:34.483Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>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</p>
  <p>Suggest &quot;git clone git@lab.civicrm.org:extensions/sparkpost.git&quot;. Then delete the .git folder in the sparkpost extension directory as you probably don't want to keep that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-23T19:31:09.177Z
Answers.LastActivityDate: 2022-08-23T19:31:09.177Z
Answers.UserDisplayName: petednz - fuzion
Body: <blockquote>
  <p>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.</p>
  </blockquote>
  <p>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 &gt; System Settings &gt; Outgoing mail (SparkPost) I receive the above error on the screen.</p>
  <p>I have cleared caches and double-checked paths.</p>
  <p>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: <a href="https://lab.civicrm.org/dev/core/-/issues/2563" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/-/issues/2563</a>. It only comes up here as part of the exceptions thrown verbiage in the codebase.</p>
  <p>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.</p>
  <p>Please let me know what else I can try, thank you!</p>
  <pre><code>    Jul 31 22:09:44  [error] 
  $Fatal Error Details = array:3 [
    &quot;message&quot; =&gt; &quot;Cannot decrypt token. Invalid format.&quot;
    &quot;code&quot; =&gt; null
    &quot;exception&quot; =&gt; Civi\Crypto\Exception\CryptoException {#1368
      -errorData: array:1 [
        &quot;error_code&quot; =&gt; 0
      ]
      #cause: null
      -_trace: null
      #message: &quot;Cannot decrypt token. Invalid format.&quot;
      #code: 0
      #file: &quot;/var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/Civi/Crypto/CryptoToken.php&quot;
      #line: 206
      trace: {
        /var/www/html/fosterclub/docroot/sites/all/modules/contrib/civicrm/Civi/Crypto/CryptoToken.php:206 {
          ›   default:
          ›     throw new CryptoException(&quot;Cannot decrypt token. Invalid format.&quot;);
          › }
        }
        /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 { …}
      }
    }
  ]
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-02T01:28:25.833Z
Comments.Text: I found this reported issue, which may be the same: https://lab.civicrm.org/extensions/sparkpost/-/issues/110
Comments.UserDisplayName: Christia
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-03T20:27:40.293Z
Comments.Text: I'm having the same issue as the OP, and tried the answer below and it didn't work.
Comments.UserDisplayName: Zachary
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-03T22:54:06.260Z
Comments.Text: 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.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-03T22:58:19.660Z
Comments.Text: wild guess but might php version be a possible factor
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-03T23:32:27.863Z
Comments.Text: 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.
Comments.UserDisplayName: Zachary
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-05T20:28:58.713Z
Comments.Text: Hope SendGrid works for you. We tried shifting same client to SG a couple of years back and the outcome was bad due to many spammers using same IP pool and SG did nothing to help resolve. So far, cross fingers, the SP experience has been better.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-08T18:03:07.360Z
Comments.Text: Yeah, I already am seeing some of my mailings go to spam :( It would be wonderful if I could somehow resolve the above issue. Will keep posting back. Someone on the issue thread above said they were on 7.4 and it still didn't work.
Comments.UserDisplayName: Zachary
Tags: <drupal><extension><sparkpost>
Title: Configuration page for newly installed SparkPost extension error: Cannot decrypt token. Invalid format
ThreadText: # Configuration page for newly installed SparkPost extension error: Cannot decrypt token. Invalid format
  
  (Asked by: username_0 on 2022-08-01)
  
  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 { …}
      }
    }
  ]
  
  **Tags:** drupal, extension, sparkpost
  
  > **Comments:**
  > **username_0**: I found this reported issue, which may be the same: https://lab.civicrm.org/extensions/sparkpost/-/issues/110  
  > **username_1**: I'm having the same issue as the OP, and tried the answer below and it didn't work.  
  > **username_2**: 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.  
  > **username_2**: wild guess but might php version be a possible factor  
  > **username_1**: 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.  
  > **username_2**: Hope SendGrid works for you. We tried shifting same client to SG a couple of years back and the outcome was bad due to many spammers using same IP pool and SG did nothing to help resolve. So far, cross fingers, the SP experience has been better.  
  > **username_1**: Yeah, I already am seeing some of my mailings go to spam :( It would be wonderful if I could somehow resolve the above issue. Will keep posting back. Someone on the issue thread above said they were on 7.4 and it still didn't work.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2022-08-23. Score: 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.
  
  
  ---
  
  ### Answer by username_4 on 2022-08-02. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_1**: I have tried adding these settings to my civicrm.settings.php file and it has not resolved the above issue.  
  > **username_4**: Ok it's possible there's an issue in the extension, but I'll update the answer with a couple more things.  
  > **username_5**: Tried this and it didn't work.  
  > **username_2**: 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  
  > **username_2**: i then tried editing the civicrm.settings.php - no improvement. i await my technical colleague joining in this hunt tomorrow. Note, this is a much older site. is on same civi version now, but has been around for > 10 years (just in case that is part of the puzzle)  
  
  ---
  
  ### Answer by username_2 on 2022-08-23. Score: 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 git@lab.civicrm.org:extensions/sparkpost.git". Then delete the .git folder in the sparkpost extension directory as you probably don't want to keep that.
  
  
  ---
  
  