problem in encryption

Discussion in 'Python' started by jayshree, Sep 22, 2009.

  1. jayshree

    jayshree Guest

    hello ,
    The community members,

    Using following code :

    fileHandle = open ('jay1key.py','wb')
    #fileHandle = open ('jay1key.pem',rb).read()
    print fileHandle.write (data) #data variable is contains the key
    fileHandle.close()


    otp = 'jyshri69'


    pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')

    encrypted = pub_key.public_encrypt(otp, M2Crypto.RSA.pkcs1_padding)
    print "encrypted text is = "
    print "-----------------------"
    print encrypted

    the above code gives me following error :
    None
    Traceback (most recent call last):
    File "RetEnc.py", line 71, in ?
    pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')
    File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 344,
    in load_pub_key
    return load_pub_key_bio(bio)
    File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 360,
    in load_pub_key_bio
    rsa_error()
    File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 240,
    in rsa_error
    raise RSAError, m2.err_reason_error_string(m2.err_get_error())
    M2Crypto.RSA.RSAError: no start line


    not getting how to resolve it ?
    jayshree, Sep 22, 2009
    #1
    1. Advertising

  2. jayshree

    jayshree Guest

    On Sep 22, 1:44 pm, jayshree <> wrote:
    > hello ,
    > The community members,
    >
    > Using following code  :
    >
    > fileHandle = open ('jay1key.py','wb')
    > #fileHandle = open ('jay1key.pem',rb).read()
    > print fileHandle.write (data) #data variable is contains the key
    > fileHandle.close()
    >
    > otp = 'jyshri69'
    >
    > pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')
    >
    > encrypted = pub_key.public_encrypt(otp, M2Crypto.RSA.pkcs1_padding)
    > print "encrypted text is =   "
    > print "-----------------------"
    > print encrypted
    >
    > the above code gives me following error :
    > None
    > Traceback (most recent call last):
    >   File "RetEnc.py", line 71, in ?
    >     pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')
    >   File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 344,
    > in load_pub_key
    >     return load_pub_key_bio(bio)
    >   File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 360,
    > in load_pub_key_bio
    >     rsa_error()
    >   File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 240,
    > in rsa_error
    >     raise RSAError, m2.err_reason_error_string(m2.err_get_error())
    > M2Crypto.RSA.RSAError: no start line
    >
    > not getting how to resolve it ?


    the key looks like this :
    -----BEGIN RSA PUBLIC KEY-----
    mQGiBEpz7VIRBADAt9YpYfYHJeGA6d
    +G261FHW1uA0YXltCWa7TL6JnIsuxvh9vImUoyMJd6
    1xEW4TuROTxGcMMiDemQq6HfV9tLi7ptVBLf/8nUEFoGhxS
    +DPJsy46WmlscKHRIEdIkTYhp
    uAIMim0q5HWymEqqAfBLwJTOY9sR+nelh0NKepcCqwCgvenJ2R5UgmAh
    +sOhIBrh3OahZEED
    /2sRGHi4xRWKePFpttXfb2hry2/jURPae/wYfuI6Xw3k5EO593veGS7Zyjnt+7mVY1N5V/
    ey
    rfXaS3R6GsByG/eRVzRJGU2DSQvmF+q2NC6v2s4KSzr5CVKpn586SGUSg/
    aKvXY3EIrpvAGP
    rHum1wt6P9m9kr/4X8SdVhj7Jti6A/0TA8C2KYhOn/
    hSYAMTmhisHan3g2Cm6yNzKeTiq6/0
    ooG/
    ffcY81zC6+Kw236VGy2bLrMLkboXPuecvaRfz14gJA9SGyInIGQcd78BrX8KZDUpF1Ek
    KxQqL97YRMQevYV89uQADKT1rDBJPNZ+o9f59WT04tClphk/
    quvMMuSVILQaamF5c2ggPGph
    eXNocmVlQGdtYWlsLmNvbT6IZgQTEQIAJgUCSnPtUgIbAwUJAAFRgAYLCQgHAwIEFQIIAwQW
    AgMBAh4BAheAAAoJEFjpOQ2vjFvzS0wAn3vf1A8npIY/DMIFFw0/
    eGf0FNekAKCBJnub9GVu
    9OUY0nISQf7uZZVyI7kBDQRKc+1SEAQAm7Pink6S5+kfHeUoJVldb
    +VAlHdf7BdvKjVeiKAb
    dFUa6vR9az+wn8V5asNy/
    npEAYnHG2nVFpR8DTlN0eO35p78qXkuWkkpNocLIB3bFwkOCbff
    P3yaCZp27Vq+9182bAR2Ah10T1KShjWTS/
    wfRpSVECYUGUMSh4bJTnbDA2MAAwUEAIcRhF9N
    OxAsOezkiZBm+tG4BgT0+uWchY7fItJdEqrdrROuCFqWkJLY2uTbhtZ5RMceFAW3s
    +IYDHLL
    PwM1O+ZojhvAkGwLyC4F
    +6RCE62mscvDJQsdwS4L25CaG2Aw97HhY7+bG00TWqGLb9JibKie
    X1Lk+W8Sde/4UK3Q8tpbiE8EGBECAA8FAkpz7VICGwwFCQABUYAACgkQWOk5Da+MW/
    MAAgCg
    tfUKLOsrFjmyFu7biv7ZwVfejaMAn1QXEJw6hpvte60WZrL0CpS60A6Q
    -----END RSA PUBLIC KEY-----
    jayshree, Sep 22, 2009
    #2
    1. Advertising

  3. >>>>> jayshree <> (j) wrote:

    >j> hello ,
    >j> The community members,


    >j> Using following code :


    >j> fileHandle = open ('jay1key.py','wb')
    >j> #fileHandle = open ('jay1key.pem',rb).read()
    >j> print fileHandle.write (data) #data variable is contains the key
    >j> fileHandle.close()



    >j> otp = 'jyshri69'



    >j> pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')


    [Why do you give your key file a .py extension? .pem would be better.]

    Your key in the next posting (when the broken lines are reconstructed)
    seems to be in PKCS1 format. That's what -----BEGIN RSA PUBLIC KEY-----
    indicates. However, M2Crypto.RSA.load_pub_key expects the key in X.509
    format, which starts with -----BEGIN PUBLIC KEY----- and also has a
    different format inside, so just changing the header and trailer won't
    work.

    Anyway, I doubt that the key is correct as it seems to large for just a
    public key. How was that key generated?
    --
    Piet van Oostrum <>
    URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
    Private email:
    Piet van Oostrum, Sep 22, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guenther Sohler

    Encryption Problem

    Guenther Sohler, Oct 17, 2003, in forum: Perl
    Replies:
    1
    Views:
    501
    Jim Gibson
    Oct 20, 2003
  2. Natty Gur

    Re: encryption problem

    Natty Gur, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    504
    Natty Gur
    Jul 16, 2003
  3. Fernando Barsoba

    Data type problem in encryption algorithm

    Fernando Barsoba, Nov 25, 2005, in forum: C Programming
    Replies:
    11
    Views:
    611
    Flash Gordon
    Nov 26, 2005
  4. Fernando Barsoba

    problem with encryption function sending hex values

    Fernando Barsoba, Nov 27, 2005, in forum: C Programming
    Replies:
    2
    Views:
    302
    Fernando Barsoba
    Nov 28, 2005
  5. Replies:
    1
    Views:
    348
    Walter Roberson
    Aug 13, 2006
Loading...

Share This Page