NativeScript / nativescript-cli

Command-line interface for building NativeScript apps
https://www.npmjs.com/package/nativescript
Apache License 2.0
1.04k stars 195 forks source link

failed to decrypt safe contents entry: javax.crypto.BadPaddingException #5570

Closed EdJones closed 3 years ago

EdJones commented 3 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug When building for Android release, ns build android... gives

Execution failed for task ':app:signReleaseBundle'.
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.

despite both Play Store and key tool accepting the keystore/key as valid. To Reproduce Create a key store. try to build app bundle with ns build android --release --aab --keystore...

Expected behavior Produces lab without error Sample project Can provide

Additional context This occurred with a newly created app as well as one a couple years old.

Here's the issue: It just didn't like the password. The keystore password had a $ in it. Changing the password had no effect if the $ was still in it. In fact, having the wrong password gave the same error. But using a password with no $ worked fine.

rigor789 commented 3 years ago

I did a test and can confirm I get the same (on macos, windows seems to be fine with it) result with a $ in the password. The issue is with how you pass the password to the CLI - $ has special meaning, so the following:

ns build --release --aab --key-store-password somepass$word

is received by the CLI as

ns build --release --aab --key-store-password somepass

because $word is an empty shell variable.

There's nothing in the CLI to fix this, you just need to either escape the $ characters with \$, or wrap the password in single quotes:

ns build --release --aab --key-store-password 'somepass$word'