Question about Rabbit's AES encryption Article

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lostme
    New Member
    • Jul 2015
    • 7

    Question about Rabbit's AES encryption Article

    Hi Rabbit,

    Can you explain the following line in the RunAES procedure (Cipher-block Chaining mode)?

    For i = 0 To (Len(oPW.Value) - 1)

    Specifically: What does oPW represent? I thought it was a string but then the 'o' made me think it was an object. I'm trying to understand the algorithm, so I'm stepping into it and having trouble resolving the opw.Value

    Thanks very much in advance.

    (z)Referring to AES Encryption Algorithm for VBA and VBScript
    Last edited by zmbd; Jul 17 '15, 07:51 PM. Reason: [z{Lost Me, moved your post to new thread, we try to keep the articles clean :)}{Added Cross Reference}]
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The oPW is a textbox on a form that holds the password that will be used to encrypt the file. You can, if you wish, replace it with a string.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32666

      #3
      Good work tidying this up Z :-)

      Rabbit has it covered and we can monitor it to ensure the OP gets all they need.

      Comment

      • lostme
        New Member
        • Jul 2015
        • 7

        #4
        Thanks Rabbit :) I'm going to test it out to see if it'll encrypt strings and files.

        Comment

        • lostme
          New Member
          • Jul 2015
          • 7

          #5
          Thanks very much, NeoPa.

          Comment

          • lostme
            New Member
            • Jul 2015
            • 7

            #6
            Hi Rabbit,

            I've also had to adjust a few things, namely variable declarations (as you know, VBScript doesn't require the type when declaring a variable but I'm running the code as VBA), anyway, I first ran the code passing in a file as argument, the code executed without exceptions but I checked the processed file and the text inside was still plain text, not encrypted. I also ran the code supplying a string to see if it'd obfuscate the string but it didn't.

            Do you have a sample file that you fed into the script? I'm curious as to your results after running the same code. Thanks very much in advance.

            Comment

            • lostme
              New Member
              • Jul 2015
              • 7

              #7
              Sorry, I missed the .enc version of the file, the encrypted version came with a default file launch type, I picked Notepad to open it. My further questions are:

              * How do I decrypt the same encrypted file?

              * What if I want to encrypt a string using the script? How would I modify the code to target an input string instead of file to encrypt?

              Thanks very much in advance.

              Comment

              • lostme
                New Member
                • Jul 2015
                • 7

                #8
                Another side-effect of the script is that the original file remains, so I guess if I had to implement the script, I'd have to delete the original file, otherwise the encrypted version would be compromised by the fact that its plain text version would still be available in the same location.

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  Decrypting is done by passing the .enc file into the same function. It sets the mode based on the extension. You can set that differently if you wish. For example, by passing in an additional parameter to the function that sets the mode.

                  To encrypt a string, take out the references to files and change them to strings instead, change the sub to a function, and have the function return the string result instead.

                  To remove the unencrypted version of the file, add a line of code that deletes the original file.

                  Comment

                  • lostme
                    New Member
                    • Jul 2015
                    • 7

                    #10
                    Hi Rabbit,

                    Thanks very much for the reply, sorry I've been super busy and I'm just now writing back.

                    Comment

                    Working...