473,738 Members | 10,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12982
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
Jul 17 '05 #2
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
Jul 17 '05 #3


Jerry wrote:
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.


[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********@yah oo.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********@yah oo.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 institutionaliz ation*
</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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1733
by: Krzysztof Adamski | last post by:
Hi, Is it possible in jython to map an PyLong object to other class than BigInteger (i.e. java.lang.Long) ? Thanks for you help, Krzysztof Adamski
4
6404
by: adrin | last post by:
I have to create a c++ class similar to BigInteger from java... but i have no idea, how can i implement big numbers at all(mabye store every digit in list element? :)) how is it properly done? thanks for help
113
12337
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
0
1446
by: hitler123 | last post by:
can anyone say me how to define BigInteger as a datatype in an xsd. this xsd i am uising in the xmlbeans.
19
6465
by: shana07 | last post by:
I don't understand about this program is doing. Could someone please tell me what it is about. Because I have gcd function in one program that calls this function. Thanks a lot switch (opcode) { case GCD: out = b1.gcd(b2).toString(); break; /** * Returns a BigInteger whose value is the greatest common divisor of * <tt>abs(this)</tt> and <tt>abs(val)</tt>. Returns 0 if * <tt>this==0 &amp;&amp;...
2
2849
by: gemacjr1201 | last post by:
I am creating a GUI for class and need help with my program. My program takes 2 big integers and adds them together. First how do I declare my 2 Big Integers and then add them together? I have read the API docs , but still need help. Thanks! import java.math.BigInteger; public class Integer { private BigInteger IntegerONE; // both entered as strings from GUI private BigInteger IntegerTWO; public Integer() {
2
2781
by: jehugaleahsa | last post by:
Hello: I am currently working on a some simple (not really) classes called BigInteger and BigRational. They are pretty much identical to Java's BigInteger and BigDecimal classes, respectfully. BigRational is really simple and it just maintains a dividend and denominator and then prints out the decimal form when done with the calculation.
6
13573
by: mearvk | last post by:
Does C++ or C have something roughly equivalent to this: http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html What I need is a way to quickly convert between decimal and binary and from char*/string to a numeric representation. Thanks!
11
10513
by: imranisb | last post by:
Hi, Im developing RSA cryptography based application in VC#.Net 2.0 and need to use "BigInteger.probablePrime()". I know that VC#.Net 2.0 doesn't have the BigInteger class but found that one buddy created BigInteger class but it is missing some overloading function like BigInteger.probablePrime(). The code of the BigInteger class developed in the C#.Net can be found here: http://www.codeproject.com/KB/cs/biginteger.aspx
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.