Getting Exception: Object type cannot be passed to C codeConvert bytes to a string?csv.Error: iterator should return strings, not bytesRSA decryption of AES Session key fails with 'AttributeError: 'bytes' object has no attribute 'n'Why do I have to hexlify before decoding into ascii?Can't import ChaCha20Crypto Encryption modue in MFC application throws “Cannot load native module Crypto.Cipher._raw_ecb”pyrebase install on windows Python 3.7 failsAES OFB implementation in python with pycryptodomeHow to decode IPFS private and public key in DER/PEM format?ImportError: cannot import name 'RSA' from 'Crypto.PublicKey'

How would you translate "more" for use as an interface button?

awk assign to multiple variables at once

"before" and "want" for the same systemd service?

Is this toilet slogan correct usage of the English language?

Biological Blimps: Propulsion

Why Shazam when there is already Superman?

When were female captains banned from Starfleet?

Mimic lecturing on blackboard, facing audience

Circuit Analysis: Obtaining Close Loop OP - AMP Transfer function

How to make money from a browser who sees 5 seconds into the future of any web page?

Why the "ls" command is showing the permissions of files in a FAT32 partition?

How can ping know if my host is down

Multiplicative persistence

How much of a Devil Fruit must be consumed to gain the power?

Non-trope happy ending?

Change the color of a single dot in `ddot` symbol

Which Article Helped Get Rid of Technobabble in RPGs?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

What is the highest possible scrabble score for placing a single tile

Find the next value of this number series

A Trivial Diagnosis

How to preserve electronics (computers, iPads and phones) for hundreds of years

Microchip documentation does not label CAN buss pins on micro controller pinout diagram



Getting Exception: Object type cannot be passed to C code


Convert bytes to a string?csv.Error: iterator should return strings, not bytesRSA decryption of AES Session key fails with 'AttributeError: 'bytes' object has no attribute 'n'Why do I have to hexlify before decoding into ascii?Can't import ChaCha20Crypto Encryption modue in MFC application throws “Cannot load native module Crypto.Cipher._raw_ecb”pyrebase install on windows Python 3.7 failsAES OFB implementation in python with pycryptodomeHow to decode IPFS private and public key in DER/PEM format?ImportError: cannot import name 'RSA' from 'Crypto.PublicKey'













1















I install pip install pycryptodome on Python 3.7.2. I'm getting above exception for obj = AES.new(key, AES.MODE_CBC, iv) line. my code is:



from Crypto import Random
from Crypto.Cipher import AES
import random

def get_encryption():
try:
str = "This is input string"

key = b'abcdefghijklmnop'
iv = Random.new().read(AES.block_size)

obj = AES.new(key, AES.MODE_CBC, iv)
encrypted = obj.encrypt(str)
print(encrypted)
except Exception as e:
print(e)


I tried to all the way but not getting how to solve it.










share|improve this question




























    1















    I install pip install pycryptodome on Python 3.7.2. I'm getting above exception for obj = AES.new(key, AES.MODE_CBC, iv) line. my code is:



    from Crypto import Random
    from Crypto.Cipher import AES
    import random

    def get_encryption():
    try:
    str = "This is input string"

    key = b'abcdefghijklmnop'
    iv = Random.new().read(AES.block_size)

    obj = AES.new(key, AES.MODE_CBC, iv)
    encrypted = obj.encrypt(str)
    print(encrypted)
    except Exception as e:
    print(e)


    I tried to all the way but not getting how to solve it.










    share|improve this question


























      1












      1








      1


      1






      I install pip install pycryptodome on Python 3.7.2. I'm getting above exception for obj = AES.new(key, AES.MODE_CBC, iv) line. my code is:



      from Crypto import Random
      from Crypto.Cipher import AES
      import random

      def get_encryption():
      try:
      str = "This is input string"

      key = b'abcdefghijklmnop'
      iv = Random.new().read(AES.block_size)

      obj = AES.new(key, AES.MODE_CBC, iv)
      encrypted = obj.encrypt(str)
      print(encrypted)
      except Exception as e:
      print(e)


      I tried to all the way but not getting how to solve it.










      share|improve this question
















      I install pip install pycryptodome on Python 3.7.2. I'm getting above exception for obj = AES.new(key, AES.MODE_CBC, iv) line. my code is:



      from Crypto import Random
      from Crypto.Cipher import AES
      import random

      def get_encryption():
      try:
      str = "This is input string"

      key = b'abcdefghijklmnop'
      iv = Random.new().read(AES.block_size)

      obj = AES.new(key, AES.MODE_CBC, iv)
      encrypted = obj.encrypt(str)
      print(encrypted)
      except Exception as e:
      print(e)


      I tried to all the way but not getting how to solve it.







      python-3.x pycryptodome






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 4:26







      Anil Jagtap

















      asked Mar 6 at 12:10









      Anil JagtapAnil Jagtap

      3741421




      3741421






















          1 Answer
          1






          active

          oldest

          votes


















          0














          After tried all the way I got solution. I converted key string into bytes.
          code is:



          from Crypto import Random
          from Crypto.Cipher import AES
          import random

          def get_encryption():
          try:
          strmsg = "This is input string"

          key = 'abcdefghijklmnop'
          key1 = str.encode(key)

          iv = Random.new().read(AES.block_size)

          obj = AES.new(key1, AES.MODE_CBC, iv)
          encrypted = obj.encrypt(str.encode(strmsg))
          print(encrypted)
          except Exception as e:
          print(e)





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55022837%2fgetting-exception-object-type-class-str-cannot-be-passed-to-c-code%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            After tried all the way I got solution. I converted key string into bytes.
            code is:



            from Crypto import Random
            from Crypto.Cipher import AES
            import random

            def get_encryption():
            try:
            strmsg = "This is input string"

            key = 'abcdefghijklmnop'
            key1 = str.encode(key)

            iv = Random.new().read(AES.block_size)

            obj = AES.new(key1, AES.MODE_CBC, iv)
            encrypted = obj.encrypt(str.encode(strmsg))
            print(encrypted)
            except Exception as e:
            print(e)





            share|improve this answer



























              0














              After tried all the way I got solution. I converted key string into bytes.
              code is:



              from Crypto import Random
              from Crypto.Cipher import AES
              import random

              def get_encryption():
              try:
              strmsg = "This is input string"

              key = 'abcdefghijklmnop'
              key1 = str.encode(key)

              iv = Random.new().read(AES.block_size)

              obj = AES.new(key1, AES.MODE_CBC, iv)
              encrypted = obj.encrypt(str.encode(strmsg))
              print(encrypted)
              except Exception as e:
              print(e)





              share|improve this answer

























                0












                0








                0







                After tried all the way I got solution. I converted key string into bytes.
                code is:



                from Crypto import Random
                from Crypto.Cipher import AES
                import random

                def get_encryption():
                try:
                strmsg = "This is input string"

                key = 'abcdefghijklmnop'
                key1 = str.encode(key)

                iv = Random.new().read(AES.block_size)

                obj = AES.new(key1, AES.MODE_CBC, iv)
                encrypted = obj.encrypt(str.encode(strmsg))
                print(encrypted)
                except Exception as e:
                print(e)





                share|improve this answer













                After tried all the way I got solution. I converted key string into bytes.
                code is:



                from Crypto import Random
                from Crypto.Cipher import AES
                import random

                def get_encryption():
                try:
                strmsg = "This is input string"

                key = 'abcdefghijklmnop'
                key1 = str.encode(key)

                iv = Random.new().read(AES.block_size)

                obj = AES.new(key1, AES.MODE_CBC, iv)
                encrypted = obj.encrypt(str.encode(strmsg))
                print(encrypted)
                except Exception as e:
                print(e)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 5:23









                Anil JagtapAnil Jagtap

                3741421




                3741421





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55022837%2fgetting-exception-object-type-class-str-cannot-be-passed-to-c-code%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович