curl sha1
This commit is contained in:
parent
1f3a5f7f32
commit
e0cc2d0834
@ -22,12 +22,19 @@ namespace a8
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_slist* list = nullptr;
|
||||
if (headers) {
|
||||
list = curl_slist_append(list, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
||||
}
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, content.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &_ReceiveResponse);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
|
||||
bool ok = curl_easy_perform(curl) == CURLE_OK;
|
||||
curl_easy_cleanup(curl);
|
||||
if (list) {
|
||||
curl_slist_free_all(list);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
16
a8/openssl.cc
Normal file → Executable file
16
a8/openssl.cc
Normal file → Executable file
@ -134,5 +134,21 @@ namespace a8
|
||||
return std::string((char*)md, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
std::string sha1(std::string& from)
|
||||
{
|
||||
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||
|
||||
SHA_CTX ctx;
|
||||
SHA1_Init(&ctx);
|
||||
SHA1_Update(&ctx, from.data(), from.size());
|
||||
SHA1_Final(digest, &ctx);
|
||||
|
||||
char mdString[SHA_DIGEST_LENGTH*2+1];
|
||||
for (int i = 0; i < SHA_DIGEST_LENGTH; i++){
|
||||
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
|
||||
}
|
||||
return std::string(mdString);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
1
a8/openssl.h
Normal file → Executable file
1
a8/openssl.h
Normal file → Executable file
@ -16,6 +16,7 @@ namespace a8
|
||||
void Base64Encode(const std::string& from, std::string& to);
|
||||
|
||||
std::string Sha1Encode(std::string& from);
|
||||
std::string sha1(std::string& from);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user