Encrypt and Decrypt an ArrayList

This forum was posted on Sunday, May 19, 2013 9:32:28 PM

I want to store an array list of strings in a file by encrypting it. And then I decrypt the file content and restore them to a array list. But when i decrypt the content blocks of 'Null' are there inside the content. With no 'Null' blocks rest of the text are the similar as i encoded.
public static void encryptFile(List moduleList  File fileOut) {
try {
OutputStream out = new FileOutputStream(fileOut);
out = new CipherOutputStream(out encryptCipher);
StringBuilder moduleSet = new StringBuilder();
for (String module : moduleList) {
moduleSet.append(module + "#");
} catch (java.io.IOException ex) {
System.out.println("Exception: " + ex.getMessage());
public static List decryptFile(File fileIn) {
List moduleList = new ArrayList();
byte buf = new byte16;
try {
InputStream in = new FileInputStream(fileIn);
in = new CipherInputStream(in decryptCipher);
int numRead = 0;
int counter = 0;
StringBuilder moduleSet = new StringBuilder();
while ((numRead = in.read(buf)) >= 0) {
moduleSet.append(new String(buf));
String blocks = moduleSet.split("#");
System.out.println("Items: " + blocks.length);
} catch (java.io.IOException ex) {
System.out.println("Exception: " + ex.getMessage());
return moduleList;

I attempted with UTF-16 since strings are encoded in java in UTF-16 But it only makes the o/p worst.
Your ideas will be apprised...

 Views 92 Get Source Code >>
Related Tags:

Replies on "Encrypt and Decrypt an ArrayList" :

Nobody has replied on this post , be first to post answer.

Post Your Answer/Comment:

Please Login first to post Reply !

Note: Please Put Code into <code></code> block.

Threads related to "Encrypt and Decrypt an ArrayList":