I am writing a Java application which can \"encrypt\" and consequently \"decrypt\" whatever binary file.
I am just a beginner in the \"cryptography\" area so I would
Maybe this open source library can help you:
http://www.jasypt.org/
try the sample given below. u could convert the bytes to string and then encrypt and then write it to file. reverse it while decrypting.
http://www.exampledepot.com/egs/javax.crypto/desstring.html
below u can find a sample DES enc&dec for files..
http://www.exampledepot.com/egs/javax.crypto/DesFile.html
Don't store it there! Any good encryption is based on mathematical algorithms (like AES). You may want to have a look at BouncyCastle http://www.bouncycastle.org/ - but encryption is not a simple topic, so you should get a good book to learn about its basics first!
It would probably be easier not to check the password give by the user against a global password, rather ensure that only that one password (known by the user) decrypts the ciphertext into the correct plaintext, any other password would return gibberish. This is usually how cryptography works and means you don't have to store a centralised password anywhere.
A really simple way to use a password to encrypt is to use XOR, here is some pseudo code
for(byte in file)
{
Byte newByte = byte ^ (byte) password[i];
outputFile.write(newByte);
i = (i + 1) password.length();
}
This is based on the identity that (x XOR y) XOR y = x, all you need to do is encrypt/decrypt with the same password.
Use the password to encrypt your data. You could for example repeat the password so that it matches the byte array's length and then do something like
data[i] = data[i] >> password[i];
Edit: if you wanted to store the password, you would have to encrypt it. Which - at least when using symmetrical cryptosystems - will be inherently insecure.