I get an error trying to generate a key for certain devices. I’m able to reproduce the error on a Samsung Galaxy Note running 4.4.2.
I created a small app to only generate a key by copying the code line by line from the Android developer page https://developer.android.com/training/articles/keystore.html under “Generating a New Private Key.”
The error seems to occur in kpg.generateKeyPair(), inside AndroidKeyPairGenerator.java:
The Java KeyGenerator class (javax.crypto.KeyGenerator) is used to generate symmetric encryption keys.A symmetric encryption key is a key that is used for both encryption and decryption of data, by a symmetric encryption algorithm. In this Java KeyGenerator tutorial I will show you how to generate symmetric encryption keys. Creating a KeyStore in JKS Format. This section explains how to create a KeyStore using the JKS format as the database format for both the private key, and the associated certificate or certificate chain. By default, as specified in the java.security file, keytool uses JKS as the format of the key and certificate databases (KeyStore.
![Java Keystore Generate Aes Key Java Keystore Generate Aes Key](https://www.misterpki.com/wp-content/uploads/2020/01/generate-secret-key.png)
and in KeyStore.java:
The mBinder.generate() call seems to return 2 which means the keystore is locked?
The error might be somewhat related to this issue with the keystore https://code.google.com/p/android/issues/detail?id=177459&q=could%20not%20generate%20key%20in%20keystore&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
A few things I’ve tried individually and combinations of the following:
1. Setting encryption required. The result is another error: “Android keystore must be in initialized and unlocked state if encryption is required”
2. Setting a lock screen (pattern, PIN, NONE, password, swipe). Same behavior
3. Programmatically attempting to unlock or reset the credential storage with
1. Setting encryption required. The result is another error: “Android keystore must be in initialized and unlocked state if encryption is required”
2. Setting a lock screen (pattern, PIN, NONE, password, swipe). Same behavior
3. Programmatically attempting to unlock or reset the credential storage with
startActivity(new Intent('com.android.credentials.UNLOCK'));
or startActivity(new Intent('com.android.credentials.RESET'));
Attempting to unlock shows a “enter password for credential storage” message, in which no reasonable password works, and even clearing the credentials doesn’t help.How to&Answers:
While I don’t know the full answer, I can help continue your search. The binder implementation on the other side of mBinder is the native keystore. If I recall fully, it’s behavior is to either 1) support key operations at a software level, or 2) delegate to a OEM-provided keymaster library that (presumably) interfaces to the OEM’s hardware-backed keystore. More info on this here, here, and here.
Note: I’ll forgo SO’s normal policy of pulling the external link content into the answer, since I’m linking you out to three articles that are all >1 page and it seems a bit ridiculous to post a 6-page answer 😉
Java Keystore Generate Aes Key Bank
Answer:
You can use this class . This is works min SDK 18 and above. You can create Android Keystore key , decrypt and encrypt simple text.
Answer:
If your code is OK then remember that you need to set up a PIN/PW/Fingerprint (Secure unlock) for your device so that the keystore starts functioning. A simple swipe will give such error if you try to generate keypairs. Battlefield 1942 key code generator.
Answer:
Java Keystore Pkcs12
I think this is the right direction:
Right click on project > Android Tools > Export Signed Application Package
The Export Android Application wizard appears.
Select the project I want to export, click Next.
The Keystore Selection screen appears.
Right click on project > Android Tools > Export Signed Application Package
The Export Android Application wizard appears.
Select the project I want to export, click Next.
The Keystore Selection screen appears.
Keytool Generate Keystore
Tags: android, javajava