Java Encryption newbie

  • Thread starter Marco A. Cruz Quevedo
  • Start date
M

Marco A. Cruz Quevedo

i everybody,

I want to develop a simple encryption program that does the following
(in pseudocode)
----
mycert = opencert("mycert.cer");
publickey pubkey = mycert.getPublicKey();

string message = readfile("MessageFile.txt");

string scrambled = encrypt(message,pubkey);

writefile("encrypted",scrambled);

----

The certificate was generated by keytool and exported by

keytool -exportcert -alias myself -rfc -file mycert.cer

I have been reading many java documentation files but I cannot figure
out which classes I should use.

Any advice will be greatly appreciated.

Regards,

Marco A. Cruz Quevedo.
 
J

Joshua Cranmer

mycert = opencert("mycert.cer");

<http://java.sun.com/javase/6/docs/api/java/security/cert/CertificateFactory.html>
has a bit of code that tells you how to get a
java.security.cert.Certificate from a file.
publickey pubkey = mycert.getPublicKey();

This is even more trivial.
string message = readfile("MessageFile.txt");

I presume you know how to use Java file I/O already, so I won't even
bother here.
string scrambled = encrypt(message,pubkey);

Encryption and decryption are handled via javax.crypto.Cipher. Note that
this is done in blocks, so you presumably would need reading/writing in
blocks as opposed to streamed I/O.
 
F

Fredrik Jonson

Marco A. Cruz Quevedo wrote:
I want to develop a simple encryption program that does the following.

Take a good look and see if using keyczar is a viable option for you.

Keyczar is a open source crypto library initially developed by google
because "Cryptography is easy to get wrong.". It designed to use safe
defaults and offer a high level api to reduce programmatical faults.

http://www.keyczar.org/
 
M

Marco A. Cruz Quevedo

rossum said:
This may not be what you want to do. Public Key (asymmetric)
encryption is secure but slow. It is not generally used for large
quantities of data. It is more common to use the public key to
encrypt and send a short private key and then to use that private key
to encrypt a large volume of data using AES or some other symmetric
encryption system.

rossum
Thank you very much for your comment but in fact, the messages I need
to encrypt are less than 1Kb, so it suits my needs.

Regards,

Marco A. Cruz Quevedo
 
A

Arne Vajhøj

Thank you very much for your comment but in fact, the messages I need
to encrypt are less than 1Kb, so it suits my needs.

The technique suggested by rossum is usually preferred
for data sizes >32 bytes or so.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top