欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

hmac_sha1(c++示例)

介绍 评论 失效链接反馈

#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

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