question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Caused by java.security.InvalidKeyException: Only SecretKey is supported

See original GitHub issue

Issue by Lucashuang0802 Wednesday Jan 23, 2019 at 09:11 GMT _Originally opened as https://github.com/googlesamples/android-FingerprintDialog/issues/55_


Got an exception like this by using the standard approach to authenticate via fingerprint:

   private void generateKey() throws Exception {
        try {
            keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
            keyStore.load(null);
            keyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                    .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                    .setUserAuthenticationRequired(true)
                    .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
                    .build());
            keyGenerator.generateKey();
        } catch (KeyStoreException
                | NoSuchAlgorithmException
                | NoSuchProviderException
                | InvalidAlgorithmParameterException
                | CertificateException
                | IOException exc) {
            exc.printStackTrace();
            throw new Exception(exc);
        }
    }
    private boolean initCipher() {
        try {
            cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
            throw new RuntimeException("Failed to get Cipher", e);
        }

        try {
            keyStore.load(null);
            SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return true;
        } catch (KeyPermanentlyInvalidatedException e) {
            return false;
        } catch (KeyStoreException | CertificateException
                | UnrecoverableKeyException | IOException
                | NoSuchAlgorithmException | InvalidKeyException e) {
            throw new RuntimeException("Failed to init Cipher", e);
        }
    }
Caused by java.security.InvalidKeyException: Only SecretKey is supported
       at com.android.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(OpenSSLCipher.java:436)
       at com.android.org.conscrypt.OpenSSLCipher.engineInit(OpenSSLCipher.java:261)
       at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2668)
       at javax.crypto.Cipher.tryCombinations(Cipher.java:2575)
       at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2480)
       at javax.crypto.Cipher.chooseProvider(Cipher.java:567)
       at javax.crypto.Cipher.init(Cipher.java:831)
       at javax.crypto.Cipher.init(Cipher.java:772)

Mostly users got crashes by 8 and 9 starts getting crashes: screen shot 2019-01-23 at 1 10 10 am

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
nic0lettecommented, Dec 9, 2019

Hi. Sorry, but the issues here are intended for problems or feature requests for the Security samples themselves, rather than for general support issues. I’d recommend checking out Stack Overflow and asking your question there.

0reactions
codingjeremycommented, Sep 6, 2019

Comment by vrajeshpatel Tuesday Jun 11, 2019 at 12:31 GMT


You have set UserAuthenticationRequired as true. If you want to keep this, Device lock needs to be set via pin code or fingerprint as per @batschz or you can setUserAuthenticationRequired(false).

Read more comments on GitHub >

github_iconTop Results From Across the Web

InvalidKeyException: Only SecretKey is supported
I have recently started seeing this error in devices. java.security.InvalidKeyException: Only SecretKey is supported ...
Read more >
Caused by java.security.InvalidKeyException: Only SecretKey ...
Got an exception like this by using the standard approach to authenticate via fingerprint: private void generateKey() throws Exception { try ...
Read more >
Java Examples for java.security.InvalidKeyException
This java examples will help you to understand the usage of java.security.InvalidKeyException. These source code samples are taken from different open ...
Read more >
Attempt to use a key from secure key store fails on Android 12 ...
We are protecting our app data by a key from Android secure keystore, ... Caused by: java.security.InvalidKeyException: Keystore operation failed
Read more >
src/main/java/org/conscrypt/OpenSSLCipher.java - Google Git
import java.security.spec. ... SecureRandom random) throws InvalidKeyException, ... throw new InvalidKeyException("Only SecretKey is supported");.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found