Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Sir,I have searched in google for finding SHA(Secure Hash Algorithm) using C program and came to know about Openssl library which is to be used for finding SHA etc.,

I have downloaded Openssl binary Rar file and extracted it.But I don't know how to add Openssl library to my visual studio because I need this header file for finding SHA

C++
#include <openssl/sha.h>


On extracting the openssl rar fie I see many folder, c source and header files which is quite confusing.

I usually prefer codeblocks for programming with C and C++ so I don't know how to add those libraries in visual studio.
What should I do now?
Is there any other better ways for finding SHA using C/C++ programming even manually?

Kindly help me with this.
Posted
Updated 30-Sep-18 20:01pm

It depends if you have static library files (.lib) or only source code (.c)

If you only have c-files, then you can add them to your project and include the header files where you need to. How to: Add Existing Items to a Project[^]

If you have library files, see this link: MSDN: .Lib Files as Linker Input[^]

[UPDATE]
To copy the contents of the contents from one variable to another you can use memcpy_s[^]

C++
char szSha1Value[40];
memcpy_s(szSha1Value, sizeof(szSha1Value), *arr, strlen(*arr));

(Not exactly sure if the dereferencing of arr is correct, see Pointers[^])
 
Share this answer
 
v3
Comments
[no name] 4-Dec-15 4:37am    
Sir, I tried and added a header file and my code works in the way like this

char **arr = CALL_Function("C:\\Users\\User\\Desktop\\hello.exe");

and prints the SHA-1 value as
"3bc2e8ca3fdc172eb752131c391adf2f"
now my question is how to I copy this value into a new variable so that I can compare the variables.
George Jonsson 4-Dec-15 4:43am    
Well, what does the variable arr contain? (very descriptive name, I must say)
[no name] 4-Dec-15 4:51am    
By using the header file we can call a function named "CALL_FUNCTION" the variable char **arr is used to find the SHA-1 value by CALL_FUNCTION(char *string);where char *string is the location of the file.
I just gave arr any name can be given.
George Jonsson 4-Dec-15 4:52am    
So the variable arr contains the calculated SHA1 value?
[no name] 4-Dec-15 4:53am    
Yes sir.
Here[^] are the build instructions for Windows (32bit, there's a different doc for 64bit). After you've built and installed the openssl libraries, add the include paths (openssl/include or inc32/) to your Visual Studio library paths and the library binary paths (openssl/lib or out32dll/) to your linker paths.

There are also pre-compiled versions available[^], comes with an installer since it has to install several parts.
 
Share this answer
 
Comments
[no name] 4-Dec-15 4:36am    
Sir, I tried and added a header file and my code works in the way like this

char **sha = CALL_Function("C:\\Users\\User\\Desktop\\hello.exe");

and prints the SHA-1 value as
"3bc2e8ca3fdc172eb752131c391adf2f"
now my question is how to I copy this value into a new variable so that I can compare the variables.
I get it it was hard work for a long time. I installed openssl-1.1.0h and make it works with Visual Studio 2017
I create a subfolder in c:\openssl-1.1.0h and put the files of openssl in this folder.
(I have Visual Studio in Spanish, so it is possible that some menu option are not correctly named). This is my experience, not really a tutorial. It was a lot of work.
The following are the steps:

I.- I Download OpenSSL (openssl-1.1.0h), PERL and NASM

II.- I installed PERL and NASM

III.- I installed OpenSSL, but it was not easy
1) I open a console windows, but not the normal (not the console get by writing cmd or somesthing like that)
I open a console from native Tool, this is a subfolder from visual studio:
Start->All Programs->Visual Studio 2017->Visual Studio Tools->VC->System Symbol of Native Tools x64
2) cd \openssl-1.1.0h
3) path c;\program files\nasm\;%path%;
4) ppm install dmake
5) perl Configure VC-WIN64A
6) nmake
7) nmake test
8) nmake install
And finally it works the installation!!!

IV.- When I tried to compile the sw in visual studio it did not compile. There was a linker problem with a library file (I guess libcrypto.lib).
1) Property Page of the Project->Linker->Input->Additional Dependences.
The file including the path need to be written here, in my case:
C:\openssl-1.1.0h\libcrypto.lib
2) With a console tool included in Visual Studio I analyzed this file: Dumpbin
I analyzed the report of the dumbin and I realized that the library file was for x64, so I had to create a x64 configuration in Visual Studio.
This was also not natural:...

V.- Compilation for x64. I found this help web page (in spanish)

1) In visual Studio 2017 ->;Compile->;Configuration Manager
2) In Configuration of Active Solution I let "Debug" (the initial value) and in Platform of Active Configuration I selected "New", and then a new windows opened
3) in the field "write or select the new platform" I select "win32" and in the field "Copy the configuration from" I selected x64 and I click in Accept.The active windows was closed.
4) After that the last windows, that has the list of project context (in my case only one context was available) I let "Debug" in the Configuration field, and in the Platform I selected "x64" and I click on close button
5) I close the project complete and I opened again (I am not sure if this is necessary, but I did it and works)
6) After that I compiled the project.....

The project did not compile, but the error list was different now.The openssl include files were not found. The reason was that the
include openssl folder was not added to the project. I add openssl-1.10h and openssl-1.10h\include to the project.
To do this I carry out the following steps.
1) In solution explorer with the project selected (this means one level bellow the solution) I clicked on the spanner icon (to get the property of the project)
2) In configuration property-> VC Directory->Include file directory I added the folders openssl-1.10h and openssl-1.10h\include
3) I compile again and the project did not compile properly, but now the compile report some PDB files missing (I read in a forum that those files were not so important) and after that a message that the project was close with the code (0xc0000135). This was a file missing, but there was not identificated by the compile report. To know what was the file I had to use a tool for this. This tool needs to be downloaded and put on a folder (installation was very easy, not icon was added, only downloaded and copied in a folder):
Dependency Walker. In the folder I executed the file "depends.exe".
4) I select the file open option in the menu
5) In a windows opened, 5 panels are available. Some of them were clean and in other was a tree (like folders tree) a file missing with a
yellow icon and a message that say the file was missing (libcrypto-1_1-x64.dll). I double clicked on this file and the file was looked for
in the folder were the exe file of my project was found.
6) I Copied the (libcrypto-1_1-x64.dll) file .exe file of my project (myproject.exe). Any ways some files were missing, but I guess this was not important.
7) I compiled the project again
And the project Compiled!!!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900