增加SHA256
This commit is contained in:
@@ -7,6 +7,7 @@ namespace ylib
|
|||||||
namespace codec
|
namespace codec
|
||||||
{
|
{
|
||||||
ylib::buffer sha1(const ylib::buffer& data);
|
ylib::buffer sha1(const ylib::buffer& data);
|
||||||
|
ylib::buffer sha256(const ylib::buffer& data);
|
||||||
std::string md5(const ylib::buffer& data);
|
std::string md5(const ylib::buffer& data);
|
||||||
std::string to_utf8(const std::string& gbk);
|
std::string to_utf8(const std::string& gbk);
|
||||||
std::string to_gbk(const std::string& utf8);
|
std::string to_gbk(const std::string& utf8);
|
||||||
|
|||||||
@@ -43,11 +43,17 @@ ylib::buffer ylib::codec::sha1(const ylib::buffer& data)
|
|||||||
SHA1_Final((unsigned char*)result.data(), &sha1);
|
SHA1_Final((unsigned char*)result.data(), &sha1);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
//std::stringstream ss;
|
}
|
||||||
//for (int i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
ylib::buffer ylib::codec::sha256(const ylib::buffer& data)
|
||||||
// ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
|
{
|
||||||
//}
|
ylib::buffer result;
|
||||||
//return ss.str();
|
// SHA256 输出 32 字节
|
||||||
|
result.resize(32);
|
||||||
|
SHA256_CTX sha256;
|
||||||
|
SHA256_Init(&sha256);
|
||||||
|
SHA256_Update(&sha256, data.data(), data.size());
|
||||||
|
SHA256_Final((unsigned char*)result.data(), &sha256);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
std::string ylib::codec::to_utf8(const std::string &gbk)
|
std::string ylib::codec::to_utf8(const std::string &gbk)
|
||||||
|
|||||||
Reference in New Issue
Block a user