Javascript - Python RSA encryption interoperability

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Evren Esat Ozkan

    Javascript - Python RSA encryption interoperability

    Hello,

    I'm trying to encrypt a string with RSA. But it needs to be compitable
    with Dave's JavaScript RSA implementation* . I'm already read and tried
    lots of different things about RSA and RSA in Python. But could not
    produce the same result with the javascript library.

    My experiments could be seen at: http://dpaste.com/hold/60741/

    * JavaScript RSA Library: http://www.ohdave.com/rsa/

    Python libraries which I tried;
    * PyCrtypo: http://www.amk.ca/python/code/crypto.html
    * rsa library from http://www.stuvel.eu/rsa

    How could I create the same results with the JS library in Python.


    Any help would be appreciated

    Evren,
  • marek.rocki@wp.pl

    #2
    Re: Javascript - Python RSA encryption interoperabilit y

    Evren Esat Ozkan napisa³(a):
    Hello,
    >
    I'm trying to encrypt a string with RSA. But it needs to be compitable
    with Dave's JavaScript RSA implementation* . I'm already read and tried
    lots of different things about RSA and RSA in Python. But could not
    produce the same result with the javascript library.
    >
    My experiments could be seen at: http://dpaste.com/hold/60741/
    >
    * JavaScript RSA Library: http://www.ohdave.com/rsa/
    >
    Python libraries which I tried;
    * PyCrtypo: http://www.amk.ca/python/code/crypto.html
    * rsa library from http://www.stuvel.eu/rsa
    >
    How could I create the same results with the JS library in Python.
    >
    >
    Any help would be appreciated
    >
    Evren,
    It seems that this Javascript is doing weird things to its input,
    namely processing it in reverse. Try encrypting ciphertext[::-1]
    instead of just ciphertext.

    public_modulus_ hex = '9F2E..snip..4B C7'
    public_exponent _hex = '10001'
    public_modulus = int(public_modu lus_hex, 16)
    public_exponent = int(public_expo nent_hex, 16)

    def encrypt(plainte xt_text):
    # Beware, plaintext must be short enough to fit in a single block!
    plaintext = int(plaintext_t ext.encode('hex '), 16)
    ciphertext = pow(plaintext, public_exponent , public_modulus)
    return '%X' % ciphertext # return hex representation

    print encrypt('12345' )
    print encrypt('12345'[::-1]) # Will return the value compatible with
    JS output

    Regards,
    Marek

    Comment

    • Evren Esat Ozkan

      #3
      Re: Javascript - Python RSA encryption interoperabilit y

      Hi,

      Thank you very much. Your code is worked like a charm and saved my
      honeymoon :)

      Thanks again,
      Evren


      On Jul 4, 6:19 pm, marek.ro...@wp. pl wrote:
      Evren Esat Ozkan napisa³(a):
      >
      >
      >
      >
      >
      Hello,
      >
      I'm trying to encrypt a string with RSA. But it needs to be compitable
      with Dave's JavaScript RSA implementation* . I'm already read and tried
      lots of different things about RSA and RSA in Python. But could not
      produce the same result with the javascript library.
      >
      My experiments could be seen at:http://dpaste.com/hold/60741/
      >
      * JavaScript RSA Library:http://www.ohdave.com/rsa/
      >
      Python libraries which I tried;
      * PyCrtypo:http://www.amk.ca/python/code/crypto.html
      * rsa library fromhttp://www.stuvel.eu/rsa
      >
      How could I create the same results with the JS library in Python.
      >
      Any help would be appreciated
      >
      Evren,
      >
      It seems that this Javascript is doing weird things to its input,
      namely processing it in reverse. Try encrypting ciphertext[::-1]
      instead of just ciphertext.
      >
      public_modulus_ hex = '9F2E..snip..4B C7'
      public_exponent _hex = '10001'
      public_modulus = int(public_modu lus_hex, 16)
      public_exponent = int(public_expo nent_hex, 16)
      >
      def encrypt(plainte xt_text):
              # Beware, plaintext must be short enough to fit in a single block!
              plaintext = int(plaintext_t ext.encode('hex '), 16)
              ciphertext = pow(plaintext, public_exponent , public_modulus)
              return '%X' % ciphertext # return hex representation
      >
      print encrypt('12345' )
      print encrypt('12345'[::-1]) # Will return the value compatible with
      JS output
      >
      Regards,
      Marek

      Comment

      • Paul Rubin

        #4
        Re: Javascript - Python RSA encryption interoperabilit y

        Evren Esat Ozkan <sleytr@gmail.c omwrites:
        I'm trying to encrypt a string with RSA. But it needs to be compitable
        with Dave's JavaScript RSA implementation* .
        What exactly are you trying to do? That Javascript implementation
        looks like bad news. If you're trying to secure a web page, use SSL,
        don't mess around with trying to encrypt it with Javascript.

        Comment

        Working...