469,352 Members | 2,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

RSA Encryption using BigInteger

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?
Thanks for your help.

Jerry
Jul 17 '05 #1
5 12654
On the wall of the virtual bathroom stall, je******@hotmail.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
Jul 17 '05 #2
no***@celeron.local (Wiseguy) wrote in message news:<3f********@127.0.0.1>...
On the wall of the virtual bathroom stall, je******@hotmail.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.getBytes() ;
BigInteger[] bigdigits = new BigInteger[digits.length] ;
for( i = 0 ; i < bigdigits.length ; i++ ) {
temp[0] = digits[i] ;
bigdigits[i] = new BigInteger( temp ) ;
}
BigInteger[] encrypted = new BigInteger[bigdigits.length] ;
for( i = 0 ; i < bigdigits.length ; i++ ) {
encrypted[i] = bigdigits[i].modPow( E, N ) ;
}
return(encrypted) ;
}

public static String decrypt(BigInteger[] encrypted, BigInteger D,
BigInteger N) {
int i ;
BigInteger[] decrypted = new BigInteger[encrypted.length] ;
for( i = 0 ; i < decrypted.length ; i++ ) {
decrypted[i] = encrypted[i].modPow(D, N);
}
char[] charArray = new char[decrypted.length] ;
for( i = 0 ; i < charArray.length ; i++ ) {
charArray[i] = (char) (decrypted[i].intValue());
}
return( new String(charArray)) ;
}
Regards,

Jerry
Jul 17 '05 #3


Jerry wrote:
no***@celeron.local (Wiseguy) wrote in message news:<3f********@127.0.0.1>...
On the wall of the virtual bathroom stall, je******@hotmail.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.


[snippage]

Don't you just love these liberal colleges that grant degrees for
impractical feats, rather than actual, practical displays of skill?

[/rant]

Jul 17 '05 #4
On the wall of the virtual bathroom stall, Alexander Bryanson <ar********@yahoo.com> scratches:
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.


[snippage]

Don't you just love these liberal colleges that grant degrees for
impractical feats, rather than actual, practical displays of skill?

[/rant]


<rant>
I don't mind impractical for educational exercises as long as it teaches
concepts. What troubles me is anyone at the graduate level not knowing how
to use OO constructs to extract data from one class and interface it with
another class. By the time anyone has a BS in comp sci they should fully
understand computing languages and especially the OO paradigm.

As a university educated computer scientist who hasn't been able to find
work in nearly three years I'm very alarmed that many who are still working
simply don't have the skills or the education to make things work, yet they
get a paycheck and I don't.

</rant>

RE: BigInteger to Socket
Download and refer to the J2SE API specification from SUN. Everything you need
is in there...
Jul 17 '05 #5


Wiseguy wrote:
On the wall of the virtual bathroom stall, Alexander Bryanson <ar********@yahoo.com> scratches:
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.

[snippage]

Don't you just love these liberal colleges that grant degrees for
impractical feats, rather than actual, practical displays of skill?

[/rant]

<rant>
I don't mind impractical for educational exercises as long as it teaches
concepts. What troubles me is anyone at the graduate level not knowing how
to use OO constructs to extract data from one class and interface it with
another class. By the time anyone has a BS in comp sci they should fully
understand computing languages and especially the OO paradigm.

As a university educated computer scientist who hasn't been able to find
work in nearly three years I'm very alarmed that many who are still working
simply don't have the skills or the education to make things work, yet they
get a paycheck and I don't.


Ah, but you're a university educated computer scientist! You should be
able to get a job anywhere! We should give our job to someone who's not
as well off as you, cause they need it more.

see Atlas Shrugged, Objectivism, Irrational Capitalism, et. al.
</rant>
<rant>
sigh... that's the truth.

The truth of the matter is, if people aren't self-motivated during
college and take the trouble to learn the language on their own, they
won't. I really think that college and secondary education comp. prog.
classes aren't concerned with teaching the langauge per se. They're
more interested, it seems, in teaching vague concepts like "Analytical
thinking" and "Logical systems"

*mutters about institutionalization*
</rant>

</thread hijacking>
RE: BigInteger to Socket
Download and refer to the J2SE API specification from SUN. Everything you need
is in there....


Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Krzysztof Adamski | last post: by
4 posts views Thread by adrin | last post: by
19 posts views Thread by shana07 | last post: by
2 posts views Thread by gemacjr1201 | last post: by
6 posts views Thread by mearvk | last post: by
11 posts views Thread by imranisb | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.