RSA Encryption using BigInteger

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry

    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
  • Wiseguy

    #2
    Re: RSA Encryption using BigInteger

    On the wall of the virtual bathroom stall, jerry270@hotmai l.com (Jerry) scratches:[color=blue]
    > 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?[/color]

    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


    Comment

    • Jerry

      #3
      Re: RSA Encryption using BigInteger

      [email protected] ocal (Wiseguy) wrote in message news:<3f693689_ [email protected]>...[color=blue]
      > On the wall of the virtual bathroom stall, jerry270@hotmai l.com (Jerry) scratches:[color=green]
      > > 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?[/color]
      >
      > 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[/color]

      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

      Comment

      • Alexander Bryanson

        #4
        Re: RSA Encryption using BigInteger



        Jerry wrote:
        [color=blue]
        > [email protected] ocal (Wiseguy) wrote in message news:<3f693689_ [email protected]>...
        >[color=green]
        >>On the wall of the virtual bathroom stall, jerry270@hotmai l.com (Jerry) scratches:
        >>[color=darkred]
        >>>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?[/color]
        >>
        >>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[/color]
        >
        >
        > 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.
        >[/color]

        [snippage]

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

        [/rant]

        Comment

        • Wiseguy

          #5
          Re: RSA Encryption using BigInteger

          On the wall of the virtual bathroom stall, Alexander Bryanson <arcimpluse@yah oo.com> scratches:[color=blue][color=green][color=darkred]
          >>>Using RSA for the bulk of your traffic is going to be innefficient.
          >>>
          >>>-Wiseguy[/color]
          >>
          >>
          >> 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.
          >>[/color]
          >
          > [snippage]
          >
          > Don't you just love these liberal colleges that grant degrees for
          > impractical feats, rather than actual, practical displays of skill?
          >
          > [/rant][/color]

          <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...


          Comment

          • Alexander Bryanson

            #6
            Re: RSA Encryption using BigInteger



            Wiseguy wrote:[color=blue]
            > On the wall of the virtual bathroom stall, Alexander Bryanson <arcimpluse@yah oo.com> scratches:
            >[color=green][color=darkred]
            >>>>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.
            >>>[/color]
            >>
            >>[snippage]
            >>
            >>Don't you just love these liberal colleges that grant degrees for
            >>impractical feats, rather than actual, practical displays of skill?
            >>
            >>[/rant][/color]
            >
            >
            > <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.[/color]

            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.
            [color=blue]
            > </rant>[/color]

            <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>
            [color=blue]
            > RE: BigInteger to Socket
            > Download and refer to the J2SE API specification from SUN. Everything you need
            > is in there....[/color]

            Comment

            Working...