5

I'm trying to publish my first app on Google Play and I encounter difficulties. Let me explain my problem to you: My app compiles and I want to generate a signed apk... That doesn't work with android studio (Build--> generate signed budle/apk) and I had the next error message:

erreur keytool : java.io.FileNotFoundException: C:\Users\sebla\Desktop\AndroidApp\jdk-11.0.1\bin\mykeystore.jks (Accès refusé)

Then, I succeeded in creating the keystore (via cmd):
C:\Users\sebla\Desktop\AndroidApp\jdk-11.0.1\bin>keytool -genkey -v -keystore appkeystore.keystore -alias permisKey -keyalg RSA -keysize 2048 -validity 10000

but now I got the following error message when generating the signed apk:

Something went wrong with the encryption tool: Get Key failed: Given final block not properly padded
java.security.UnrecoverableKeyException: Get Key failed: Given final block not properly padded
    at sun.security.pkcs12.PKCS12KeyStore.engineGetKey(PKCS12KeyStore.java:410)
    at sun.security.provider.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:96)
    at sun.security.provider.JavaKeyStore$DualFormatJKS.engineGetKey(JavaKeyStore.java:70)
    at java.security.KeyStore.getKey(KeyStore.java:1023)
    at com.google.wireless.android.vending.developer.signing.tools.extern.export.KeystoreHelper.extractPrivateKey(KeystoreHelper.java:56)
    at com.google.wireless.android.vending.developer.signing.tools.extern.export.KeystoreHelper.getPrivateKey(KeystoreHelper.java:35)
    at com.google.wireless.android.vending.developer.signing.tools.extern.export.ExportEncryptedPrivateKeyTool.run(ExportEncryptedPrivateKeyTool.java:98)
    at org.jetbrains.android.exportSignedPackage.ExportSignedPackageWizard$2.run(ExportSignedPackageWizard.java:241)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:750)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
    at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:395)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:305)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:989)
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:845)
    at com.sun.crypto.provider.PKCS12PBECipherCore.implDoFinal(PKCS12PBECipherCore.java:399)
    at com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede.engineDoFinal(PKCS12PBECipherCore.java:431)
    at javax.crypto.Cipher.doFinal(Cipher.java:2165)
    at sun.security.pkcs12.PKCS12KeyStore.engineGetKey(PKCS12KeyStore.java:348)
    ... 20 more
------------------------------------

Some help would be much appreciated as I'm completely lost and frustrated not being able to publish my app. Do I have any code to implement in manifest or gradle to remove that error?

Seb
  • 51
  • 1
  • 4
  • Possible duplicate of [Given final block not properly padded](https://stackoverflow.com/questions/8049872/given-final-block-not-properly-padded) – Martin Zeitler Feb 02 '19 at 16:39
  • Thank you for your help but it's not a duplicate as I didn't write any code related to encryption. It's just I want generate a signed apk from Android Studio – Seb Feb 02 '19 at 17:08
  • 2
    You can create new keystore from Android Studio. https://stackoverflow.com/a/29621643/6168272. Once you use this keystore and publish your app to Play Store, keep it somewhere safe. – Ranjan Feb 02 '19 at 17:23
  • Ranjan, I tried this way but I had the following error: erreur keytool : java.io.FileNotFoundException: C:\Users\sebla\Desktop\AndroidApp\jdk-11.0.1\bin\appkeystore.keystore (Accès is denied) – Seb Feb 02 '19 at 17:47
  • A few things. (a) It looks like you are using quite strange place to put your `keystore.properties` and `mykeystore.jks` files. (b) It also seem that your compiler is expecting a `PKCS12`-type keystore, whereas *Android Studio* has normally used another default. (I know the new gradle whines about this, telling you to convert to pkcs12, but when I did that I got weird errors too. (c) Try to follow my [instructions here](https://stackoverflow.com/a/43230396/1147688). – not2qubit Apr 02 '19 at 12:43

1 Answers1

1

I got the same error message after generating a keystore and signing and publishing the APK with Codemagic.

My issue is that the command to generate the keystore only asked for the password of the keystore, which was then applied to the key. I found this out explicitly opening the keystore and unlocking the key using Keystore explorer.

Double check that (1) your key password is correct (not just keystore password) and (2) your key password is being used by gradle in codesinging correctly.

craastad
  • 5,167
  • 5
  • 27
  • 43