Hi,

I am very new to cryptography.

My requirement is mentioned as below steps :

1. Generate a file on webserver ->
2. Encrypt using password
3. Download the encrypted file and encrypted key file
4. Send both these files to end user
5. End User will launch Applet using jnlp to decrypt the file.
6. User will input encrypted file and encrypted key file and Decypted File will be placed on the client machine.

I have written Encryption and Decryption logic... Encryption is working fine where as Decryption is working only when I am running/debugging the code. When I created a jar, it is not able to execute following code, returning blank.

public void process(String inFilePath, String outFilePath, String encKeyFilePath) {
File encryptedKeyFile = new File(encKeyFilePath);
File fileToEncrypt = new File(inFilePath);
File unencryptedFile = new File(outFilePath);

try {
this.loadKey(encryptedKeyFile);
this.decrypt(fileToEncrypt, unencryptedFile);
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public void loadKey(File in) {
// read private key to be used to decrypt the AES key
try {
System.err.println("\n\n\n EncFile :" + in.getAbsolutePath());

int anc = getClass().getResourceAsStream("PrivateKey.key").a vailable();
byte[] encodedKey = new byte[anc];
getClass().getResourceAsStream("PrivateKey.key").r ead(encodedKey);
System.err.println("\n\n\n encodedKey(L):" + new String(encodedKey).trim().length());

PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedKey);
KeyFactory kf = null;
kf = KeyFactory.getInstance("RSA");
PrivateKey pk = null;
pk = kf.generatePrivate(privateKeySpec);
pkCipher.init(Cipher.DECRYPT_MODE, pk);
aesKey = new byte[AES_Key_Size / 8];

CipherInputStream is = null;
*is = new CipherInputStream(new FileInputStream(in), pkCipher);*
*is.read(aesKey);*
System.err.println("\n\n\n aesKey :" + new String(aesKey));
System.err.println("\n\n\n aesKey(L):" + new String(aesKey).trim().length());


is = new CipherInputStream(new FileInputStream(in), pkCipher);
is.read(aesKey);


is returning the actual key, when running/debugging in RAD but while running it as Application / Applet, returning blank.
Please let me know, what should be done to overcome this problem.