I am using AES to accomplish symmetric-key encryption.
I store the Key in a password protected KeyStore.
the api exposes the following for loading the key from keystore
keyStore.load(inputStream, keyStorePassword.toCharArray());
so everytime when i want to enrypt or decrypt , i have to pass the inputstream which is atleast in my opinion a performance hit as it has to read the content everytime afresh.
Could you anyone please help me out with the strategy of storing it in memory and from then on accessing it and converting to a InputStream?
Note :
i did try to read the contents of the keystore to String (UTF-8)and convert it to InputStream and passed it to the api .But it spit out following exception
java.io.IOException: Invalid
keystore form
Thanks for the responses.
I am all for the below alternative.
I would Load the keystore once and extract the SecretKey and assign to an instance or class variable of the class you are using and then use the SecretKey whenever one need to encrypt or decrypt