MultiFernet in Python assigning created list












3















I've been playing with the Fernet module in cryptography.fernet for Python 3.7 to try and create a rotating key structure, and recently discovered MultiFernet; where you provide a list to MultiFernet and are able to encode with index 0, and decode from a list of trial-and-error values within the MultiFernet list. (I hope that makes sense).



However, there seems to be a discrepancy between the way the module behaves and the documentation provided by this document, pages 9 and 10. Essentially, if I have a pre-created list of values, MultiFernet stores the values and creates the cryptographic instance, but loses the ability to encrypt/decrypt.



My code:



from cryptography.fernet import Fernet,MultiFernet

keystore =
message = b"foo bar"

for x in range(4):
keystore.append(Fernet.generate_key())

f = MultiFernet(keystore) # storing the list keystore creates a cryptographic instance here at f

token = f.encrypt(message) # Get error here, shown below


The error message:



Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib64/python3.7/site-packages/cryptography/fernet.py", line 151, in encrypt return self._fernets[0].encrypt(msg)
AttributeError: 'bytes' object has no attribute 'encrypt'


Using the same key from the keystore in a single



d = Fernet(keystore[0])


will provide success, but attempting to follow the recipe as the documentation shows that this



g = MultiFernet([keystore[0],keystore[1]]) 


returns the same error as above (even extracting the keys to individual variables, where key1 = keystore[0], ect)



So I'm at a loss here. Any thoughts?










share|improve this question



























    3















    I've been playing with the Fernet module in cryptography.fernet for Python 3.7 to try and create a rotating key structure, and recently discovered MultiFernet; where you provide a list to MultiFernet and are able to encode with index 0, and decode from a list of trial-and-error values within the MultiFernet list. (I hope that makes sense).



    However, there seems to be a discrepancy between the way the module behaves and the documentation provided by this document, pages 9 and 10. Essentially, if I have a pre-created list of values, MultiFernet stores the values and creates the cryptographic instance, but loses the ability to encrypt/decrypt.



    My code:



    from cryptography.fernet import Fernet,MultiFernet

    keystore =
    message = b"foo bar"

    for x in range(4):
    keystore.append(Fernet.generate_key())

    f = MultiFernet(keystore) # storing the list keystore creates a cryptographic instance here at f

    token = f.encrypt(message) # Get error here, shown below


    The error message:



    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    File "/usr/lib64/python3.7/site-packages/cryptography/fernet.py", line 151, in encrypt return self._fernets[0].encrypt(msg)
    AttributeError: 'bytes' object has no attribute 'encrypt'


    Using the same key from the keystore in a single



    d = Fernet(keystore[0])


    will provide success, but attempting to follow the recipe as the documentation shows that this



    g = MultiFernet([keystore[0],keystore[1]]) 


    returns the same error as above (even extracting the keys to individual variables, where key1 = keystore[0], ect)



    So I'm at a loss here. Any thoughts?










    share|improve this question

























      3












      3








      3








      I've been playing with the Fernet module in cryptography.fernet for Python 3.7 to try and create a rotating key structure, and recently discovered MultiFernet; where you provide a list to MultiFernet and are able to encode with index 0, and decode from a list of trial-and-error values within the MultiFernet list. (I hope that makes sense).



      However, there seems to be a discrepancy between the way the module behaves and the documentation provided by this document, pages 9 and 10. Essentially, if I have a pre-created list of values, MultiFernet stores the values and creates the cryptographic instance, but loses the ability to encrypt/decrypt.



      My code:



      from cryptography.fernet import Fernet,MultiFernet

      keystore =
      message = b"foo bar"

      for x in range(4):
      keystore.append(Fernet.generate_key())

      f = MultiFernet(keystore) # storing the list keystore creates a cryptographic instance here at f

      token = f.encrypt(message) # Get error here, shown below


      The error message:



      Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "/usr/lib64/python3.7/site-packages/cryptography/fernet.py", line 151, in encrypt return self._fernets[0].encrypt(msg)
      AttributeError: 'bytes' object has no attribute 'encrypt'


      Using the same key from the keystore in a single



      d = Fernet(keystore[0])


      will provide success, but attempting to follow the recipe as the documentation shows that this



      g = MultiFernet([keystore[0],keystore[1]]) 


      returns the same error as above (even extracting the keys to individual variables, where key1 = keystore[0], ect)



      So I'm at a loss here. Any thoughts?










      share|improve this question














      I've been playing with the Fernet module in cryptography.fernet for Python 3.7 to try and create a rotating key structure, and recently discovered MultiFernet; where you provide a list to MultiFernet and are able to encode with index 0, and decode from a list of trial-and-error values within the MultiFernet list. (I hope that makes sense).



      However, there seems to be a discrepancy between the way the module behaves and the documentation provided by this document, pages 9 and 10. Essentially, if I have a pre-created list of values, MultiFernet stores the values and creates the cryptographic instance, but loses the ability to encrypt/decrypt.



      My code:



      from cryptography.fernet import Fernet,MultiFernet

      keystore =
      message = b"foo bar"

      for x in range(4):
      keystore.append(Fernet.generate_key())

      f = MultiFernet(keystore) # storing the list keystore creates a cryptographic instance here at f

      token = f.encrypt(message) # Get error here, shown below


      The error message:



      Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "/usr/lib64/python3.7/site-packages/cryptography/fernet.py", line 151, in encrypt return self._fernets[0].encrypt(msg)
      AttributeError: 'bytes' object has no attribute 'encrypt'


      Using the same key from the keystore in a single



      d = Fernet(keystore[0])


      will provide success, but attempting to follow the recipe as the documentation shows that this



      g = MultiFernet([keystore[0],keystore[1]]) 


      returns the same error as above (even extracting the keys to individual variables, where key1 = keystore[0], ect)



      So I'm at a loss here. Any thoughts?







      python python-3.x cryptography






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 18:51









      NanotechMagusNanotechMagus

      468




      468
























          1 Answer
          1






          active

          oldest

          votes


















          2














          After more research, I realized that the Fernet encryption must be applied after the key is generated for use in the MultiFernet token creation.



          Example:



          from cryptography.fernet import Fernet,MultiFernet

          keystore =
          keyfinal =

          message = b"foo bar"
          for x in range(4):

          keystore.append(Fernet.generate_key()) # generates the initial keys
          keyfinal.append(Fernet(keystore[x])) # Applies Fernet encryption to make usable keys

          f = MultiFernet(keyfinal) # Set up MultiFernet on the keyfinal list
          s = Fernet(keystore[2]) # Take a key from the initial keystore for single key encryption

          token = s.encrypt(message) # encrypt using single key

          print(f.decrypt(token)) # decrypt using MultiFernet
          b"foo bar"





          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%2f53461358%2fmultifernet-in-python-assigning-created-list%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









            2














            After more research, I realized that the Fernet encryption must be applied after the key is generated for use in the MultiFernet token creation.



            Example:



            from cryptography.fernet import Fernet,MultiFernet

            keystore =
            keyfinal =

            message = b"foo bar"
            for x in range(4):

            keystore.append(Fernet.generate_key()) # generates the initial keys
            keyfinal.append(Fernet(keystore[x])) # Applies Fernet encryption to make usable keys

            f = MultiFernet(keyfinal) # Set up MultiFernet on the keyfinal list
            s = Fernet(keystore[2]) # Take a key from the initial keystore for single key encryption

            token = s.encrypt(message) # encrypt using single key

            print(f.decrypt(token)) # decrypt using MultiFernet
            b"foo bar"





            share|improve this answer




























              2














              After more research, I realized that the Fernet encryption must be applied after the key is generated for use in the MultiFernet token creation.



              Example:



              from cryptography.fernet import Fernet,MultiFernet

              keystore =
              keyfinal =

              message = b"foo bar"
              for x in range(4):

              keystore.append(Fernet.generate_key()) # generates the initial keys
              keyfinal.append(Fernet(keystore[x])) # Applies Fernet encryption to make usable keys

              f = MultiFernet(keyfinal) # Set up MultiFernet on the keyfinal list
              s = Fernet(keystore[2]) # Take a key from the initial keystore for single key encryption

              token = s.encrypt(message) # encrypt using single key

              print(f.decrypt(token)) # decrypt using MultiFernet
              b"foo bar"





              share|improve this answer


























                2












                2








                2







                After more research, I realized that the Fernet encryption must be applied after the key is generated for use in the MultiFernet token creation.



                Example:



                from cryptography.fernet import Fernet,MultiFernet

                keystore =
                keyfinal =

                message = b"foo bar"
                for x in range(4):

                keystore.append(Fernet.generate_key()) # generates the initial keys
                keyfinal.append(Fernet(keystore[x])) # Applies Fernet encryption to make usable keys

                f = MultiFernet(keyfinal) # Set up MultiFernet on the keyfinal list
                s = Fernet(keystore[2]) # Take a key from the initial keystore for single key encryption

                token = s.encrypt(message) # encrypt using single key

                print(f.decrypt(token)) # decrypt using MultiFernet
                b"foo bar"





                share|improve this answer













                After more research, I realized that the Fernet encryption must be applied after the key is generated for use in the MultiFernet token creation.



                Example:



                from cryptography.fernet import Fernet,MultiFernet

                keystore =
                keyfinal =

                message = b"foo bar"
                for x in range(4):

                keystore.append(Fernet.generate_key()) # generates the initial keys
                keyfinal.append(Fernet(keystore[x])) # Applies Fernet encryption to make usable keys

                f = MultiFernet(keyfinal) # Set up MultiFernet on the keyfinal list
                s = Fernet(keystore[2]) # Take a key from the initial keystore for single key encryption

                token = s.encrypt(message) # encrypt using single key

                print(f.decrypt(token)) # decrypt using MultiFernet
                b"foo bar"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 19:58









                NanotechMagusNanotechMagus

                468




                468
































                    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%2f53461358%2fmultifernet-in-python-assigning-created-list%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

                    Wiesbaden

                    Marschland

                    Dieringhausen