Ah! Thanks! We may have a documentation bug then, I followed a couple of
examples in the API docs. I will look at fixing and documenting and will
update this ticket with results.
On Tuesday, May 7, 2013, Legrandin <email address hidden> wrote:
> The line:
>
> message = 'To be encrypted'
>
> should be:
>
> message = b'To be encrypted'
>
> In Python 3, strings are not encoded and therefore cannot be encrypted
> (unless one silently performs some arbitrary encoding like Latin 1). In
> Python 2, strings and encoded strings (that is, a "bytes" object) were
> mixed and your example would have worked.
>
> See here:
>
> http://eli.thegreenplace.net/2012/01/30/the-bytesstr-dichotomy-in-
> python-3/
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1177614
>
> Title:
> Cannot encrypt with RSA in python 3.3
>
> Status in Python Cryptography Toolkit:
> New
>
> Bug description:
> Hi everyone, I can't encrypt a message using RSA in python 3.3.
> Python 3.3 virtualenv with pyCrypto:
>
> (pyCrypto-3.3) s946259:pyCrypto cclamb$ python test.py
> Traceback (most recent call last):
> File "test.py", line 9, in <module>
> ciphertext = cipher.encrypt(message)
> File
> "/Users/cclamb/PycharmProjects/interpreters/pyCrypto-3.3/lib/python3.3/site-packages/Crypto/Cipher/PKCS1_OAEP.py",
> line 150, in encrypt
> db = lHash + ps + bchr(0x01) + message
> TypeError: can't concat bytes to str
>
> Python 2.7 virtualenv with pyCrypto:
>
> (pyCrypto-2.7) s946259:pyCrypto cclamb$ python test.py
> ??םB??;?
> ??q??ڠ??s?o6???{ٍyT?B?qb?o??
> ??fp?AC?]C?|???j? ?s??.
>
> ?r????(?@_?6?5A[??"???6:?HX??da,q?;?"??爝F?W?8?iG
>
> ՚?? JH???u??
>
>
> x??Z?t??ok?$?a???Ym??S?b?M͈w?/????
> ?~T??/@?/??9?B?'???'p??m???>???.?O??ndS?~????Q,?308???y
>
> Here's the contents of test.py:
>
> from Crypto.PublicKey import RSA
> from Crypto import Random
> from Crypto.Cipher import PKCS1_OAEP
>
> rng = Random.new().read
> message = 'To be encrypted'
> key = RSA.generate(2048, rng)
> cipher = PKCS1_OAEP.new(key)
> ciphertext = cipher.encrypt(message)
>
> print(ciphertext)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/pycrypto/+bug/1177614/+subscriptions
>
Ah! Thanks! We may have a documentation bug then, I followed a couple of
examples in the API docs. I will look at fixing and documenting and will
update this ticket with results.
On Tuesday, May 7, 2013, Legrandin <email address hidden> wrote:
> The line: eli.thegreenpla ce.net/ 2012/01/ 30/the- bytesstr- dichotomy- in- /bugs.launchpad .net/bugs/ 1177614 encrypt( message) cclamb/ PycharmProjects /interpreters/ pyCrypto- 3.3/lib/ python3. 3/site- packages/ Crypto/ Cipher/ PKCS1_OAEP. py", ?s?o6?? ?{ٍyT?B? qb?o?? ?@_?6?5A[ ??"???6: ?HX??da, q?;?"?? 爝F?W?8? iG ?ok?$?a? ??Ym??S? b?M͈w?/ ???? ?/??9?B? '???'p? ?m???>? ??.?O?? ndS?~?? ??Q,?308? ??y encrypt( message) /bugs.launchpad .net/pycrypto/ +bug/1177614/ +subscriptions
>
> message = 'To be encrypted'
>
> should be:
>
> message = b'To be encrypted'
>
> In Python 3, strings are not encoded and therefore cannot be encrypted
> (unless one silently performs some arbitrary encoding like Latin 1). In
> Python 2, strings and encoded strings (that is, a "bytes" object) were
> mixed and your example would have worked.
>
> See here:
>
> http://
> python-3/
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Cannot encrypt with RSA in python 3.3
>
> Status in Python Cryptography Toolkit:
> New
>
> Bug description:
> Hi everyone, I can't encrypt a message using RSA in python 3.3.
> Python 3.3 virtualenv with pyCrypto:
>
> (pyCrypto-3.3) s946259:pyCrypto cclamb$ python test.py
> Traceback (most recent call last):
> File "test.py", line 9, in <module>
> ciphertext = cipher.
> File
> "/Users/
> line 150, in encrypt
> db = lHash + ps + bchr(0x01) + message
> TypeError: can't concat bytes to str
>
> Python 2.7 virtualenv with pyCrypto:
>
> (pyCrypto-2.7) s946259:pyCrypto cclamb$ python test.py
> ??םB??;?
> ??q??ڠ?
> ??fp?AC?]C?|???j? ?s??.
>
> ?r????(
>
> ՚?? JH???u??
>
>
> x??Z?t?
> ?~T??/@
>
> Here's the contents of test.py:
>
> from Crypto.PublicKey import RSA
> from Crypto import Random
> from Crypto.Cipher import PKCS1_OAEP
>
> rng = Random.new().read
> message = 'To be encrypted'
> key = RSA.generate(2048, rng)
> cipher = PKCS1_OAEP.new(key)
> ciphertext = cipher.
>
> print(ciphertext)
>
> To manage notifications about this bug go to:
> https:/
>