If you want to install an application on Android, the apk must be digitally signed with a certificate. For example, when you test your application on the emulator, Android Studio signs the apk with a debug certificate. The first time when you run or debug a project in Android Studio, a debug keystore and certificate is automatically created using the Android SDK tools in $HOME/.android/debug.keystore. Also the keystore is initialized and the key password is set.
As a security measure the debug certificate needs to be used only for testing and for debug builds. This certificate is not secure for using on app stores.
For later runs/debugs Android Studio automatically stores the debug signing configuration so that we do not need to enter it every time we launch the app. The signing configuration contains the keystore location $HOME/.android/debug.keystore, keystore password, key name and key password. This debug signing configuration used at run/debug is not available for editing. You can create a signing config for your release builds.
Steps for generating and uploading key and keystore:
From here we continue to sign the app with the key stored in the newly created keystore. You can skip the first two steps if you are already in the window at the 3rd step:
For more details on application signing and distribution check App Signing
In this task will see how Android applications are signed:
In this task will create a signing configuration for different build types.
Add an activity to the project. Include an EditText and a Button in the first activity. When the user types a text and presses the button, it will send the text to the second activity through an intent (putExtra). In the second activity, get the message from the Intent and display it in the TextView.
In the first activity generate a symmetric key using KeyGenerator for HmacSha256 algorithm. Save this key in a Singleton (that can be accessed from both activities). Then generate the HMAC of the text introduced by the user (using MAC with HmacSha256 algorithm) and send the HMAC along with the initial message (through the Intent). In the second activity, obtain the HMAC from the Intent, obtain the Singleton, get the symmetric key and recompute the HMAC. If the HMAC is valid (equal with the recomputed one), Display the message “Data is unmodified”.
Send the data and HMAC as byte arrays in the Intent. Use Arrays.equals() for byte arrays comparison.
String secret = "secret"; String message = "important message"; Mac sha256HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(),"HmacSHA256"); sha256HMAC.init(secretkey); byte[] secretMessageBytes = sha256HMAC.doFinal(message.getBytes())