Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple AES

Simple AES

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comsecurity
11 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U User 10623478

    I have a question that is think should be rather simple, I also feel it is not a copy of a question from years back. I am new to programing in general and I have only been doing it on and off for a few years. I use the VS2012 compiler & GNU GCC with C & C++. My question is really simple and I will try to explain this so everyone can understand. I want to make two functions that can encrypt or decrypt strings using AES or rinjdael. http://pastebin.com/Gw0RLBNR[^] The paste above is what I am talking about, it uses two functions one teaEncode and one teaDecode. I want to figure out how to make an equivalent to the tea system above but with AES. https://github.com/seonggwang/miniature-AES[^] Now I understand some of you would link me to like the one below. WinAES: A C++ AES Class[^] I'll be blunt I have been trying to make a function to encrypt/decrypt data in C++ under VS2012 using many different page on git. But the problem is few of them want to compile and I really don't know how to fix many of the issue they bring up. So I really am just asking for a AES string encryption/decryption that works under VS2012 or GCC.

    J Offline
    J Offline
    jeron1
    wrote on last edited by
    #2

    If you can't use one of the few that compile, try listing the specific compilation errors for one that does not. People here are willing to help with specific issues.

    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

    U 1 Reply Last reply
    0
    • J jeron1

      If you can't use one of the few that compile, try listing the specific compilation errors for one that does not. People here are willing to help with specific issues.

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

      U Offline
      U Offline
      User 10623478
      wrote on last edited by
      #3

      I've had problems with a few different interpretations. I don't understand the this one. A Fast and Easy to Use AES Library[^] It does some crazy stuff with int32. I have however tried using crypt CPP with code sourced from this website. http://www.mediafire.com/download/kls7loakmidciqt/AES.zip[^] That link contains the source information and the errors under vs2012.

      enhzflepE 1 Reply Last reply
      0
      • U User 10623478

        I've had problems with a few different interpretations. I don't understand the this one. A Fast and Easy to Use AES Library[^] It does some crazy stuff with int32. I have however tried using crypt CPP with code sourced from this website. http://www.mediafire.com/download/kls7loakmidciqt/AES.zip[^] That link contains the source information and the errors under vs2012.

        enhzflepE Offline
        enhzflepE Offline
        enhzflep
        wrote on last edited by
        #4

        The error messages tell you what to do. What are you having trouble with? None of your 3 invocations of cl include the switch specified in the error messages (/EHsc) Likewise, did you make the suggested change to line 28 of aes.cpp?

        "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

        U 1 Reply Last reply
        0
        • enhzflepE enhzflep

          The error messages tell you what to do. What are you having trouble with? None of your 3 invocations of cl include the switch specified in the error messages (/EHsc) Likewise, did you make the suggested change to line 28 of aes.cpp?

          "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

          U Offline
          U Offline
          User 10623478
          wrote on last edited by
          #5

          I am having problems with fixing the errors.

          enhzflepE 1 Reply Last reply
          0
          • U User 10623478

            I am having problems with fixing the errors.

            enhzflepE Offline
            enhzflepE Offline
            enhzflep
            wrote on last edited by
            #6

            Er, yes. You ah, you already made that clear in your first post. What specifically is giving you a problem?

            "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

            U 1 Reply Last reply
            0
            • enhzflepE enhzflep

              Er, yes. You ah, you already made that clear in your first post. What specifically is giving you a problem?

              "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

              U Offline
              U Offline
              User 10623478
              wrote on last edited by
              #7

              That error I am not sure how to fix it and I am pretty sure more errors will come up after it. I did attach a file with the error log in it.

              enhzflepE 1 Reply Last reply
              0
              • U User 10623478

                That error I am not sure how to fix it and I am pretty sure more errors will come up after it. I did attach a file with the error log in it.

                enhzflepE Offline
                enhzflepE Offline
                enhzflep
                wrote on last edited by
                #8

                There is one error and one warning shown there. The solution to each are in the messages! 1. Warning - arising from one of the VS supplied files. 2. Error - the compiler isn't prepared to treat a const char* as a const byte* To solve, follow the directions. I.e 1. Add the /EHsc switch to the command line. - "cl /EHsc aes.cpp" 2. Goto line 29 of aes.cpp and cast the first parameter of DefaultEncryptorWithMAC to be a const byte* Something like: DefaultEncryptorWithMAC( (const byte*)firstParam, secondParam, thirdParam);

                "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

                U 1 Reply Last reply
                0
                • enhzflepE enhzflep

                  There is one error and one warning shown there. The solution to each are in the messages! 1. Warning - arising from one of the VS supplied files. 2. Error - the compiler isn't prepared to treat a const char* as a const byte* To solve, follow the directions. I.e 1. Add the /EHsc switch to the command line. - "cl /EHsc aes.cpp" 2. Goto line 29 of aes.cpp and cast the first parameter of DefaultEncryptorWithMAC to be a const byte* Something like: DefaultEncryptorWithMAC( (const byte*)firstParam, secondParam, thirdParam);

                  "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

                  U Offline
                  U Offline
                  User 10623478
                  wrote on last edited by
                  #9

                  http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=21877[^] Well thanks but both corrections seem to be fruitless. If it is in anyway helpful here is a direct link to the original code. http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=21877[^]

                  enhzflepE 1 Reply Last reply
                  0
                  • U User 10623478

                    http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=21877[^] Well thanks but both corrections seem to be fruitless. If it is in anyway helpful here is a direct link to the original code. http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=21877[^]

                    enhzflepE Offline
                    enhzflepE Offline
                    enhzflep
                    wrote on last edited by
                    #10

                    Bother. :( I'd actually downloaded the project yesterday that you shared at MediaFire or wherever it was. I've just tried the page you linked to here, but only saw the ability to browse 10 sample projects. Going back to the article's main page also only gives the ability to download any one of the 10 samples. So, I gave it a go and carried-on anyway - loading the SLN file in your zip.I converted it to one that VS2010 was happy with and hit build. Great, no problem - it builds just fine. -- Next, I created a new win32, console project in the solution.(called Member10657083) I copied the contents of your aes.cpp file and replaced the contents of "Member10657083.cpp" with it. I also uncommented the #include stdafx.h line. Upon trying to build, I didn't get that warning you had, but still got the same error. Mistakenly, I changed

                    new DefaultEncryptorWithMAC(
                    	password.c\_str(),
                    

                    into

                    new DefaultEncryptorWithMAC(
                    	(const char\*)password.c\_str(),
                    

                    Of course, the error was exactly the same. Realizing my mistake, I then changed it to:

                    new DefaultEncryptorWithMAC(
                    	(const byte\*)password.c\_str(),
                    

                    and tried again. Bingo! The project compiled. While the project didn't successfully build, it was only linker errors, since I didn't add any to the new project. I'm tired and very rarely use VS, so I'm not going to tackle that tonight. Hope this helps. :) Let me know how you get on.

                    "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

                    U 1 Reply Last reply
                    0
                    • enhzflepE enhzflep

                      Bother. :( I'd actually downloaded the project yesterday that you shared at MediaFire or wherever it was. I've just tried the page you linked to here, but only saw the ability to browse 10 sample projects. Going back to the article's main page also only gives the ability to download any one of the 10 samples. So, I gave it a go and carried-on anyway - loading the SLN file in your zip.I converted it to one that VS2010 was happy with and hit build. Great, no problem - it builds just fine. -- Next, I created a new win32, console project in the solution.(called Member10657083) I copied the contents of your aes.cpp file and replaced the contents of "Member10657083.cpp" with it. I also uncommented the #include stdafx.h line. Upon trying to build, I didn't get that warning you had, but still got the same error. Mistakenly, I changed

                      new DefaultEncryptorWithMAC(
                      	password.c\_str(),
                      

                      into

                      new DefaultEncryptorWithMAC(
                      	(const char\*)password.c\_str(),
                      

                      Of course, the error was exactly the same. Realizing my mistake, I then changed it to:

                      new DefaultEncryptorWithMAC(
                      	(const byte\*)password.c\_str(),
                      

                      and tried again. Bingo! The project compiled. While the project didn't successfully build, it was only linker errors, since I didn't add any to the new project. I'm tired and very rarely use VS, so I'm not going to tackle that tonight. Hope this helps. :) Let me know how you get on.

                      "When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon

                      U Offline
                      U Offline
                      User 10623478
                      wrote on last edited by
                      #11

                      That did change things but it seems to have created quite a few linker errors on my end as well.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups