1

I was advised to look here: http://exampledepot.com/egs/javax.crypto/DesFile.html for the source code of encryption/decryption using import javax.crypto. I have generated my key via keytool and now I don't know how to pass my generated keys into that application for encryption and decryption.

My situation is, that I have a XML file stored online (it stores configuration details) and before I parse it with a XML parser I have to decrypt it. First of all I should of course encrypt it, before it goes online.

Question is: How to pass my generated keys into code visible in link in first row?

Thanks

1 Answer 1

6

How to load a KeyStore is documented in the JavaDoc of the KeyStore class:

import java.io.FileInputStream;
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
// get user password and file input stream
char[] password = getPassword();
try (FileInputStream fis = new FileInputStream("C:/mykeystore.jks")) {
    ks.load(fis, password);
}

Once you have loaded the key store you can load the key:

Key myKey = ks.getKey("mykeyalias", password);

The key alias is the one you have specified using keytool. Using the myKey you can initialize the Cipher instance or use for example a CipherOutputStream / CipherInputStream

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

Comments

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.