找传奇、传世资源到传世资源站!

hmac_sha1(c++示例)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

#include <cryptlite/base64.h>
#include <cryptlite/sha1.h>
#include <cryptlite/sha256.h>
#include <cryptlite/hmac.h>
#include <boost/cstdint.hpp>

using namespace cryptlite;

// base64 encoding
std::string b64 = base64::encode_from_string("foobarbuz");

std::vector<boost::uint8_t> decoded_v;
base64::decode(b64, decoded_v);

std::string decoded_str;
base64::decode(b64, decoded_str);

boost::shared_array<boost::uint8_t> arr;
std::size_t len;
boost::tie(arr, len) = base64::decode_to_array(b64);

// sha1 hash
boost::uint8_t sha1digest[sha1::HASH_SIZE];
sha1::hash("foobar", sha1digest);

// hex-formatted sha1 hash
std::string sha1hex = sha1::hash_hex("foobar");

// base64-formatted sha1 hash
std::string sha1base64 = sha1::hash_base64("foobar");

// sha256 hash
boost::uint8_t sha256digest[sha256::HASH_SIZE];
sha256::hash("foobar", sha256digest);

// hex-formatted sha256 hash
std::string sha256hex = sha256::hash_hex("foobar");

// base64-formatted sha256 hash
std::string sha256base64 = sha256::hash_base64("foobar");

// calculate hmac-sha1
boost::uint8_t hmacsha1digest[sha1::HASH_SIZE];
hmac<sha1>::calc("basestring", "key", hmacsha1digest);

// calculate hex-formatted hmac-sha1
std::string hmacsha1hex = hmac<sha1>::calc_hex("basestring", "key");

// calculate hmac-sha256
boost::uint8_t hmacsha256digest[sha256::HASH_SIZE];
hmac<sha256>::calc("basestring", "key", hmacsha256digest);

// calculate hex-formatted hmac-sha256
std::string hmacsha256hex = hmac<sha256>::calc_hex("basestring", "key");

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复