Tell me more ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

How to encrypt a file using private key in Java.

Adding this question, how to generate the private key for the same.

Before posting I went through some question like How to perform file encryption using 128-Bit AES? and other but those were not so useful.

Please help

share|improve this question
If you're looking for how to perform file encryption using a programming language, you probably want Stack overflow - a quick search finds these recommended libraries (note: ignore the ROT13 and OTP one) - and the javax.crypto docs should also help. Do remember to search there first, and post what you've tried and are not understanding - as it stands, this will be closed on SO too :) – Antony Vennard Jun 5 '12 at 9:50

closed as off topic by Antony Vennard Jun 5 '12 at 9:50

Questions on Cryptography Stack Exchange are expected to relate to cryptography within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

Like for the question you reference in your own, it sounds more like a programming problem. In Java, for example, you have the Java Cryptography Extension which also supports AES. You can read your file into a byte array in the memory and pass this array, along with the secret key, to the encryption methods.

As for the key, it makes sense to generate it by some random process and have it stored on a separate medium, like a USB stick. You can also enter it over the keyboard into your program, but this might be tedious if it's a reasonably secure key. A less secure but still workable way is to generate the secret key from a (reasonably secure) password you enter, e.g. by computing its hash value (SHA-1, SHA-2, MD5...).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.