I am learning to encrypt and decrypt at the minute and I have put this small piece of code together from tutorials and info on the net:
---
String bytes = toHex("Some 16 bit Key");
Key skeySpec = new SecretKeySpec(toByte(bytes), "AES");
Cipher c = Cipher.getInstance("AES/CFB8/NoPadding");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(keyFile));
oos.writeObject(skeySpec);
c.init(Cipher.ENCRYPT_MODE, skeySpec);
CipherOutputStream cos = new CipherOutputStream(new FileOutputStream(testFile), c);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(cos));
pw.println("Stand and unfold yourself");
pw.close();
oos.writeObject(c.getIV());
oos.close();
c.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(toByte(bytes)));
CipherInputStream cis = new CipherInputStream(new FileInputStream(testFile), c);
BufferedReader br = new BufferedReader(new InputStreamReader(cis));
Log.d("XXXX", br.readLine());
---
The log outputs the following:
---
*09-24 17:05:30.929: DEBUG/(15018): ��L���x$ yourself*
---
So it looks like it is encoding it all and then decoding only the last part?
Can any one explain why it would be doing that?
Edited by: Draffodx on 28-Sep-2010 04:21