简体   繁体   中英

Android Keystore Type which one should I choose?

I want to store secure data in a keystore. Therefore I use

KeyStore store = KeyStore.getInstance("JCEKS");

But Android seems to not know "JCEKS".

04-18 10:52:17.236: WARN/System.err(474): java.security.KeyStoreException: KeyStore JCEKS implementation not found

Trying JKS gives the same error. What algorithm is good to use it on android?

Android seems to be using bouncycastle provider. This is the default provider that, the api returns. To be sure which one is available as default on the device use KeyStore.getDefaultType() .

In my case this returned 'BKS'. Also there seems to be an exception when there is a '.' character in the keystore file path.

when I stored the store to a folder with the name of my package (as recommended in the Android documentation), it resulted in an exception.

you may like to check this also.

Did you load the keystore before you tried to access it? Did the error message happen right at the getInstance instruction?

Some googling has said that "PKCS12" worked for a few people, give that a go.

Use it's KeyStore keyStore = KeyStore.getInstance("PKCS12");

Create keystore with tool "KeyTools Explorer" !

You need bouncy castle key store (BKS). Take a look here

This worked for me:

KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");

Remember to call KeyStore.load(KeyStore.LoadStoreParameter param) before calling KeyStore.getEntry (String alias, KeyStore.ProtectionParameter param) , ie

keyStore.load(null);
KeyStore.Entry keyStoreEntry = keyStore.getEntry(alias, null);

This might help:

see https://github.com/nelenkov/ecdh-kx/blob/master/src/org/nick/ecdhkx/Crypto.java

static public void listAlgorithms( String algFilter ){
    java.security.Provider[] providers = java.security.Security.getProviders();
    for ( java.security.Provider p : providers ){
        String providerStr = String.format( "%s/%s/%f\n", p.getName(), p.getInfo(),
                                            p.getVersion() );
        mLog.debug( providerStr );
        Set< Service > services = p.getServices();
        List< String > algs = new ArrayList<>();
        for ( Service s : services ){
            boolean match = true;
            if ( algFilter != null ){
                match = s.getAlgorithm().toLowerCase().contains( algFilter.toLowerCase() );
            }

            if ( match ){
                String algStr = String.format( "\t%s/%s/%s", s.getType(),
                                               s.getAlgorithm(), s.getClassName() );
                algs.add( algStr );
            }
        }

        Collections.sort( algs );
        for ( String alg : algs ) mLog.debug( "\t" + alg );
        mLog.debug( "" );
    }
}//listAlgorithms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM