title: Cordova Release Build Error: Failed to read key example from store ... Cannot recover key
body: <p>I'm trying to do a release of an inherited Cordova project that has been updated and is ready to be deployed, but it throws this error when I try and build a release:</p>
  
  <p><strong>Command</strong></p>
  
  <pre><code>cordova build android -- --keystore="D:/keys/example.keystore" --storePassword=******** --alias=example
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
  :validateSigningDebug
  :packageDebug FAILED
  
  BUILD FAILED
  
  Total time: 1.836 secs
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':packageDebug'.
  &gt; com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\keys\example.keystore": Cannot recover key
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  (node:6552) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':packageDebug'.
  &gt; com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\keys\example.keystore": Cannot recover key
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  (node:6552) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>So I started researching about the error and found what seem to be similar errors on StackOverflow, and they all say <code>Failed to ready &lt;alias&gt; from store</code> the part following seems to be the distinguishing part of the error as far as I can tell this is not a duplicate since the rest all seem to be related to erroneous passwords or key tampering.</p>
  
  <p><strong>What Has Been Attempted</strong></p>
  
  <ol>
  <li><p>Initially, I thought the previous developer had provided an invalid alias so I figured out I can use <code>keytool -list -v -keystore example.keystore</code> to view the cert and there is only a single entry and the keystore alias is correct</p></li>
  <li><p>I tried using flags to get more information on the error, such as: <code>--info</code>, <code>--debug</code>, and <code>--stacktrace</code>; and none of them provided any insights</p></li>
  <li><p>Found out I can use <code>./gradlew signingReport</code> in the Cordova project, but the output reiterates that it failed because <code>Cannot recover key</code></p></li>
  <li><p>Google will manage key signing now so I was going to upload the keystore and started following the steps which required creating an app signing private key, which verified that the store password, alias, and key password are correct since I was able to create the private key for uploading.  I haven't uploaded the private key yet since I don't know what would happen if there were any issues so I wanted to initally sign a release manually before proceeding</p></li>
  <li><p>Running <code>keytool -list -v -keystore example.keystore</code> to double check the alias out of frustration I noticed a message at the bottom of the output, which I used to create a new keystore in an industry standard format:</p>
  
  <p>Warning:
  The JKS keystore uses a proprietary format. It is recommended 
  to migrate to PKCS12 which is an industry standard format using 
  "keytool -importkeystore -srckeystore NAME-mobileapps.keystore 
  -destkeystore NAME-mobileapps.keystore -deststoretype pkcs12</p></li>
  </ol>
  
  <p>Running the release build again, but using the updated keystore produces a new set of errors at the same point in the build so I'm assuming from this that it was the wrong thing to do:</p>
  
  <pre><code>:validateSigningDebug
  :packageDebug FAILED
  
  BUILD FAILED
  
  Total time: 2.224 secs
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':packageDebug'.
  &gt; com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\downloads\example-new.keystore": Get Key failed: Given final block not properly padded
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  (node:20144) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':packageDebug'.
  &gt; com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\downloads\example-new.keystore": Get Key failed: Given final block not properly padded
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  (node:20144) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <ol start="6">
  <li>Currently I'm looking into potential gradle issues based on the <code>Unhandled promise rejection</code> in the original error, but I'm just guessing now since that is likely internal and related to <code>Cannot recover key</code></li>
  </ol>
  
  <p><strong>Question</strong></p>
  
  <p>I spent all day yesterday trying to figure this out.  Can anyone suggest how to get this release built and signed?</p>