We can compute hash with OpenSSL Library. Hash method supported by OpenSSL are SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, MD5, MD4 and others.
Below is Simple example for utilize this library:
Hash Result saved in HashResult Variable.
- Declare Used Variable:
EVP_MD_CTX mdctx;
const EVP_MD *md; - Initialize Variable:
md = EVP_get_digestbyname("sha1");
EVP_MD_CTX_init(&mdctx); - Initialize Hash Process:
EVP_DigestInit_ex(&mdctx, md, NULL); - Adding data to be hashed:
EVP_DigestUpdate(&mdctx, (void*)"data-1", strlen("data-1")); - Step above can be repeated so all data has been added
- Finish Hash and get the Hash Result:
unsigned char *HashResult;
int HashLen = EVP_MD_size(md);
HashResult = new unsigned char[HashLen];
EVP_DigestFinal_ex(&mdctx, HashResult , &HashLen);
Hash Result saved in HashResult Variable.
1 comments:
Amiable post and this fill someone in on helped me alot in my college assignement. Gratefulness you seeking your information.
Post a Comment