how to encrypt files ?

my seniors had made a project which first encrypted a file and then defragmented it and then saved it to different locations.
though they used some java application for this, i think there must be some linux tool to
1. defragment a file
2. encrypt it too.
i am actually avoiding java totally , just trying something linux-specific.
just want to show 'em the linux power

thanks a lot to all of you...i have every reason to make 'em jealous
but geirha ... your method went totally off my head, can you enlighten me over whats going on here ??

there are few queries for all of you. since you all are using gpg, and i rarely know bout how it works.
1. suppose i encrypt and split a file on my linux system, can i get the original file on my friends' linux system ??

2. suppose someone accesses the encrypted (not yet split) file from windows (in a dual boot system). will he be able to see my file ?
i suppose on splitting up there should be NO way from windows to get the original file, am i right ?

3. i plan to encrypt and split some of my personal files in my pendrive.
since most of my surroundings are windoze, i may sometime need my encrypted+split files on windows too..does this have a solution ?

Re: how to encrypt files ?

gpg is GNU Privacy Guard, GNU's implementation of PGP, Pretty Good Privacy. Now let's say you create a pgp-keypair. You get a public key, and a secret key. The secret key is protected by a passphrase of your choosing, and you and only you should know this phrase. Your friend does the same, and then you trade public keys with each other. You import your friend's key to your list of keys, and he does the same.

If you want to send your friend a private message now, you encrypt it using your friend's public key. The resulting encrypted file can only be decrypted by your friend's secret key. I haven't heard of anyone decrypting a pgp-encrypted file without a secret key, so as long as your friend keeps his secret key secret, he and only he will be able to read your message.

Splitting the resulting pgp-encrypted file is thus rather pointless, it's secure enough as it is. The only reason for spliting it would be if you sent it by e-mail, which usually has a 10-20MiB limit.

Obviously, if you want to keep something for your eyes only, you encrypt it using your own public key, and whoever wants to see it will need the encrypted file, the secret key, and the passphrase. The passphrase can be very long, and contain spaces, so if you make a long sentence, it will take ages for anyone to crack. And if your secret key gets stolen, you have plenty of time to inform your friends that your public key should no longer be used.

I can explain the commands I did above too if you like, but you can do all this from the seahorse utility which is pre-installed in ubuntu. Applications -> Accessories -> Passwords and Encryption Keys.

To encrypt a file or directory, right click it and select encrypt, then choose the key you want to encrypt with from your list of keys. Decrypting is another right-click feature. To export your public key to give it to others, use the passwords and encryption keys utility I mentioned above.