Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a signed apk - Get Key failed: Given final block not properly padded

Tags:

java

android

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?

like image 840
Seb Avatar asked Feb 02 '19 15:02

Seb


1 Answers

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.

like image 128
craastad Avatar answered Oct 13 '22 23:10

craastad