• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cryptography Virgin  RSS feed

 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As the title suggests I'm totally new to Cryptography. I'm trying to write some code that will encrypt entries to a log file and decrypt them.

The original code was using a File Input/Output stream and the read() write().

So Imagine my joy at finding the CipherInputStream and CipherOutputStream classes in the Sun JCE which you can wrap around a FileInputStream and FileOutputStream.

Alas when I write() to the log file and later try and read() it back in again I either get 98% success with random gobblydegook characters in the decrypted data or I get truncation of the data.

I've trawled the net and found that its something to do with padding and using the correct encrypt/decrpyt mode.

The only examples I've found (including Sun's JCE spec) either encrypt simple strings (I can do that) or a whole file at a time.

If anyone can provide help or a URL link explaining how to append encrypted data to and read back decrypted datafrom a file I would be eternally grateful.

TIA Graham
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Security FAQ has a link to a basic example of using CiperInputStream/CipherOutputStream, and also to the solution of the bad padding problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!