add MD5  to my  MFC Application

Posted on 2005-04-05
Last Modified: 2010-07-27
I would like to  MD5 hashing ability to a dialog box application I created with MFC.
The source code is freely available from langfin but I would like to borrow only the relevant classes and then use them
in my dialog box application .
Is there anyway I can do this?
Question by:samroyc
    LVL 55

    Accepted Solution

    You can use Windows' CryptoAPI:

    Or you can use an independent one:

    Author Comment

    How can I use the Windows Crypto API to hae the MD5 hash of an entiire file instead of a string?I tried to point to a file,but
    it simply assumes that "filename" is a string.Any help would be greatly appreciated.
    LVL 55

    Expert Comment

    by:Jaime Olivares
    Look at the first article, the most recent comment solves your problem, you must process block by block, that is, you have to read file into a proper sized buffer, let's say, every 4000 bytes, and use md5 functions to partially calculate hash, continue until read last block in file (notice last block could be smaller than 4000 bytes).
    Have a look to:

    Author Comment

    I am inexperienced so I dont know how I would write that as MFC class.
    Also  there is  no "wincrypt.h" in the header file?
    langfine has this page
    where in a static library  is built for doing the MD5 there no way to "attach"the correct files,and then
    call the functions from my application?
    Thank you  
    LVL 55

    Expert Comment

    by:Jaime Olivares
    yes, you can attach MD5Checksum.h,  MD5Checksum.cpp and MD5ChecksumDefines.h into your own project, no need to build a library, I think.

    Author Comment

    I manually copied MDCheckSum.h MD5CheckSum.cpp and MD5CheckSumDefines.h into my project.I am getting compiler errors
    when I try to get my appliation to use the functions from this class.
    This is what I tried-
    Included "name_of_dialog.h" file in MD5CheckSum.cpp
    Then added a variable m_pWnd of type CDialog* in MD5CheckSum class
    Added a function void SetParent(CDiaog*,pWnd)
    And then tried to edit this function with
    I get error C2653-CMD5CheckSum is not a class
    I'd appreciate any help with this.
    LVL 55

    Expert Comment

    by:Jaime Olivares
    >Included "name_of_dialog.h" file in MD5CheckSum.cpp
    This is not a good practice. Better you can put a CMD5CheckSum object as a dialog member (inside your dialog.h class). You will need to include "CMD5CheckSum.h" in your_dialog.h.
    Then, you can use in some dialog's function at your_dialog.cpp


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    This article will show, step by step, how to integrate R code into a R Sweave document
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now