Results 1 to 4 of 4

Thread: decrypt with RSA?

  1. #1

    decrypt with RSA?

    <key1 xsi:type="soapenc:string"><!-- BASE64 Encoded -->
    i3/ZILiePzco8S6nPQ1lIJTzYrCepqZRCr6beYCcHE9O1+VWjplnl+455H7xh6zjI46WgrvvH9FU0eag8jHRuQ==
    </key1>

    <key2 xsi:type="soapenc:string">
    yEDJlFM/UJON9lyLkY0JKoxYYaOYuH58CG6bpQ6OIwbkJr31H0Fv82reQ+G81EFmR5cz9zija5fxJ7Es/9djcdFKZeybHdXL07jGKVq1gg=
    </key2>

    I've got two base64 (possible) rsa keys. The first one is 64 bytes and the second one 80 bytes long (after 'de-base64ing'). I would like to use pycrypto to input them as a rsa key. Any advice how to do that exactly (pycrypto documentation wasn't informative) and if I have to convert it somehow (possible pkcs conversion)?

  2. #2
    If you only want to en/decrypt with Python, you won't need PyCrypto.
    Python has everything you need built in.
    Here is an example with simple 64bit RSA:

    E = 0x10001
    N = 0xBEB128542A228E39
    D = 0xBA6970A36F738149
    K = 76 (which is 0x3736) -> our cleartext - we want to encrypt that
    C is our resulting encrypted message

    the encryption:
    C = K**E % N -> in Python:

    C = hex(pow(K,E,N))

    the result is: C = 0x25FC077C52595154

    the decryption:
    K = C**D % N -> in Python

    K = hex(pow(C,D,N))

    the result is: K = 0x3736

    As you can see, the pow function in Python can take a third parameter. It uses it to do a modulo operation with the result of 1. parameter to power 2. parameter.
    That's all you need.

    Regards
    darkelf

  3. #3
    Sure. But the problem might be the padding. One should never use plain RSA, as in your example, but only with PKCS padding, with extra randomness added.

    Version 1.5 is pretty simple, also to strip: after decryption the highest order byte is 00 then 02, then random != 0, and we stop at the first 00 byte.

    The data after that is the actual payload. There are some demands on the number of
    random bytes etc.

    Version 2 is harder to get right, and involves some hashing with SHA1, so
    this is best done in the context of a library that has it.

    I don't know the pycrypto library, I'd do it with the openssl command line tool
    or a C-program using libcrypto. Just be warned that RSA is not just the modular
    exponentiation, in practice the PKCS (or other) paddings are used...

  4. #4
    Quote Originally Posted by joblack View Post
    <key1 xsi:type="soapenc:string"><!-- BASE64 Encoded -->
    i3/ZILiePzco8S6nPQ1lIJTzYrCepqZRCr6beYCcHE9O1+VWjplnl+455H7xh6zjI46WgrvvH9FU0eag8jHRuQ==
    </key1>

    <key2 xsi:type="soapenc:string">
    yEDJlFM/UJON9lyLkY0JKoxYYaOYuH58CG6bpQ6OIwbkJr31H0Fv82reQ+G81EFmR5cz9zija5fxJ7Es/9djcdFKZeybHdXL07jGKVq1gg=
    </key2>

    I've got two base64 (possible) rsa keys. The first one is 64 bytes and the second one 80 bytes long (after 'de-base64ing'). I would like to use pycrypto to input them as a rsa key. Any advice how to do that exactly (pycrypto documentation wasn't informative) and if I have to convert it somehow (possible pkcs conversion)?
    This data seems like data encrypted by RSA, not the actual key.
    They are too short (and not well-formatted) to be keys. Their length seems like data encrypted with RSA-512 and RSA-640 respectively.

    (do you know more now?)

Similar Threads

  1. how decrypt swf
    By Koutedar in forum The Newbie Forum
    Replies: 2
    Last Post: October 27th, 2013, 10:08
  2. how to decrypt *.rar file ?
    By icray in forum The Newbie Forum
    Replies: 33
    Last Post: February 16th, 2009, 17:05
  3. SOFTICE : need a function for decrypt ...
    By SOLDIER8514 in forum Malware Analysis and Unpacking Forum
    Replies: 3
    Last Post: August 24th, 2002, 14:01
  4. Stream Cipher with Key to decrypt
    By Coersum in forum Malware Analysis and Unpacking Forum
    Replies: 2
    Last Post: July 30th, 2002, 22:49
  5. why not decrypt in exe ?
    By glx2k in forum RCE Cryptographics
    Replies: 3
    Last Post: March 13th, 2002, 16:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •