0

I am trying to do the AES encryption/decryption in java

I generated the secretkey using KeyGenerator. I stored the key using java keystore.

        Key myKey = KeyGenerator.getInstance("AES").generateKey();

        KeyStore.ProtectionParameter protParam =
                new KeyStore.PasswordProtection("secretpass".toCharArray());

        //For writing the secret Key
        KeyStore.SecretKeyEntry skEntry =
                new KeyStore.SecretKeyEntry((SecretKey)myKey);
        FileOutputStream fout = new FileOutputStream("test.ks");

        KeyStore ksout = KeyStore.getInstance("JCEKS");
        ksout.load(null,"changeit".toCharArray());
        ksout.setEntry("secretalias", skEntry, protParam);

I wanted to get this secretkey from this file using openssl programatically. Is it possible? If so, please give me some suggestions on how do I proceed.

Thank you in advance.

1 Answer 1

1

This is not possible as the default keystore (jks) is a proprietary format used by Java.

To exchange the key you would need something portable like PKCS#11 (which is a supported KeyStore format at least in Java 8).

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for the quick response. Is there any other way to do this ... I mean, any other standard way to achieve the exchange of key between java components and c++ components (which uses openssl).
@Gridahr He's just told you the answer to that. PKCS#11.
Where does it say that PKCS#11 is a supported keystore in Java 8? Not here.
@GregS Look here.
@UwePlonus: Those are the reserved names, nothing more. It doesn't mean that Oracle has a provider implementation of it. And they don't.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.