Title: pepk.jar fails with javax.crypto.BadPaddingException preventing Play App Signing enrollment for existing app
Problem Statement:
We are trying to enroll an existing Android app (com.clsreview.clsreview) in Google Play App Signing. We possess our original, valid private key and its password, and can successfully sign app bundles (.aab) using Gradle. However, Google's official pepk.jar tool consistently fails to encrypt our private key, returning a javax.crypto.BadPaddingException. This is completely blocking our ability to enroll in App Signing and thus to update our application on the Play Store.
Context:
- App Package: com.clsreview.clsreview (existing, published app)
- Key Type: 2048-bit RSA key within a JKS/PKCS12 keystore.
- Key Status: Not lost, password is known and verified working with keytool, openssl, and Android Gradle plugin.
Detailed Steps Taken & Troubleshooting:
- Attempted with Original JKS Keystore:
- Result: pepk.jar v1.0 failed with "Password verification failed" (misleading).
- Created Clean PKCS12 Keystore via OpenSSL:
- We successfully extracted private_key.pem and certificate.pem using OpenSSL from our original keystore, confirming key validity and password.
- We then created a pristine new_keystore.p12 using OpenSSL from these PEM files.
- Attempted with Clean new_keystore.p12 and Latest pepk.jar:
- We downloaded the latest pepk.jar from the Google Play Console's App Signing page.
- The exact command we executed was:
java -jar pepk.jar \
--keystore=new_keystore.p12 \
--alias=key0 \
--output=pepk-output.txt \
--include-cert \
--rsa-aes-encryption \
--encryption-key-path=encryption_public_key.pem \
--keystore-pass=pass:YOUR_PASSWORD \
--key-pass=pass:YOUR_PASSWORD
- Consistent Failure: This command still fails with the BadPaddingException.
- This is the full error trace received:
Error: Unable to export or encrypt the private key
java.io.IOException: keystore password was incorrect
at java.base/sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2092)
at java.base/sun.security.util.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:243)
at java.base/java.security.KeyStore.load(KeyStore.java:1479)
at
com.google.wireless.android.vending.developer.signing.tools.extern.export.KeystoreHelper.loadKeystore(KeystoreHelper.j
ava:53)
at
com.google.wireless.android.vending.developer.signing.tools.extern.export.KeystoreHelper.getKeystore(KeystoreHelper.ja
va:39)
at
com.google.wireless.android.vending.developer.signing.tools.extern.export.ExportEncryptedPrivateKeyTool.run(ExportEncr
yptedPrivateKeyTool.java:207)
at
com.google.wireless.android.vending.developer.signing.tools.extern.export.ExportEncryptedPrivateKeyTool.main(ExportEnc
ryptedPrivateKeyTool.java:165)
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry:
javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used
during decryption.
... 7 more
- Java Environment Testing:
- We tested the command using both OpenJDK 17 (our primary environment) and OpenJDK 11 (a common LTS version). The exact same BadPaddingException persists across both JDKs.
- Attempted Manual Python Implementation:
- We attempted to write Python scripts to replicate pepk.jar's functionality, but these failed due to cryptographic complexity.
Questions for the Community:
- Has anyone successfully overcome this specific javax.crypto.BadPaddingException when using pepk.jar with a demonstrably valid key? If so, what was the solution?
- Are there known specific incompatibilities between pepk.jar (even the latest versions) and PKCS12 files generated by certain OpenSSL versions or specific key formats (e.g., 2048-bit RSA keys from older origins)?
- Given that we have the raw private_key.pem and encryption_public_key.pem files, is there a reliable, documented method or an existing tool (other than pepk.jar) that can correctly generate the encrypted .pepk file required for Play App Signing enrollment?
- Are there any alternative methods for enrolling an existing app in Play App Signing when the official pepk.jar tool is demonstrably failing due to a bug?
We are completely blocked from updating our app and are seeking any insights or workarounds the community might offer.
Thank you for your time and expertise.