no***@celeron.l ocal (Wiseguy) wrote in message news:<3f******* *@127.0.0.1>...
On the wall of the virtual bathroom stall, je******@hotmai l.com (Jerry) scratches: Hi,
I am writing a Java Chatroom application that will implement
encryption of messages using the RSA algorithm using the BigInteger
class. It uses socket connections to exchange messages.
I have managed to generated the Private and Public keys and
exchanged public keys and modulus between the clients and server.
Please could someone advise me how encrypt a short message, pass the
encrypted message across a socket connection and then decrypt the
message at the receiving end.
I have tried creating a BigInteger[] encrypted message but how do I
send this across a socket connection? Or is there a better way to
encrypt the message and pass it across a socket connection?
First off I have to question the need to encrypt chatroom conversations with
strong encryption. I am an extreme privacy advocate but don't see simple
chatroom applications as needing to be that secure unless the purpose is to
converse with your alqueda (sp?) buddies without anyone eavesdropping.
That being said, RSA (especially implemented with the BigInger type) is
going to be slow and CPU intensive. In fact, applications such as ssh
don't use strong encryption for the bulk of their conversation dialog.
They use RSA or DSA for key exchange, then use a less secure stream cypher
for the normal conversation and regenerate new keys freqeuntly.
Using RSA for the bulk of your traffic is going to be innefficient.
-Wiseguy
It is a project for a degree so may not be a totally practical
solution. My problem that I still need to solve is sending an array
of BigIntegers across a socket connection.
The methods I am using for encryption and decryption are shown
below. They work when run on the same PC but I need to send the
output of the encrypt method over a socket and then use the decrypt
method at the other end. How to I pass the BigInteger array across
the socket if I am using a BufferedReader and PrintWriter?
public BigInteger[] encrypt( String message, BigInteger E,
BigInteger N ) {
int i ;
byte[] temp = new byte[1] ;
byte[] digits = message.getByte s() ;
BigInteger[] bigdigits = new BigInteger[digits.length] ;
for( i = 0 ; i < bigdigits.lengt h ; i++ ) {
temp[0] = digits[i] ;
bigdigits[i] = new BigInteger( temp ) ;
}
BigInteger[] encrypted = new BigInteger[bigdigits.lengt h] ;
for( i = 0 ; i < bigdigits.lengt h ; i++ ) {
encrypted[i] = bigdigits[i].modPow( E, N ) ;
}
return(encrypte d) ;
}
public static String decrypt(BigInte ger[] encrypted, BigInteger D,
BigInteger N) {
int i ;
BigInteger[] decrypted = new BigInteger[encrypted.lengt h] ;
for( i = 0 ; i < decrypted.lengt h ; i++ ) {
decrypted[i] = encrypted[i].modPow(D, N);
}
char[] charArray = new char[decrypted.lengt h] ;
for( i = 0 ; i < charArray.lengt h ; i++ ) {
charArray[i] = (char) (decrypted[i].intValue());
}
return( new String(charArra y)) ;
}
Regards,
Jerry