views:

322

answers:

2

I have a vector of user passwords. I would like to save this vector to a file and encrypt it. Then load and decrypt the file to get the passwords. I would like my users to enter a pass phrase to decrypt the files. Which algorithm should i choose? and How can i encrypt the vector before writing the file?

+2  A: 

Encryption in Java is done using the Java Cryptography Architecture (doc contains example code). As for which algorithm to use, AES should be fine.

However, don't use Vector - it's utterly outdated and should be replaced with ArrayList (this has nothing to do with cryptography, but using Vector marks you as someone who's been learning Java from 12 year old books).

Michael Borgwardt
It's a generalization, but there is a school of thought that says "Typing the letters A-E-S into your code? You're doing it wrong!": http://www.securityfocus.com/blogs/2009 ...but I guess someone has to. Vector makes me wish there were levels of deprecation - maybe we need a new annotation that says "this isn't broken, but there are better ways than this."
McDowell
Holy fscking sh*t! What kind of person writes a 15 page movie script to make a 2 paragraph point about applied cryptography?
Michael Borgwardt
I believe that would be Dave The Laser Unicorn. Come on, it's clever and readable. I'd pick a laser shark, myself, but ymmv.
CPerkins
I found it tedious and annoying; I had to skip to the last page and glance quickly over it to get an idea of what he was actually trying to say.
Michael Borgwardt
A: 

Hi,

I think you can checkout my other post (example included) and get a headstart.

http://stackoverflow.com/questions/1219377/few-characters-missing-after-decryption

Basically you just need to use CipherInputStream & CipherOutputStream, and that's it! :)

janetsmith