跳到主要内容

hmac_sha1

简介

用于hmac_sha1效验码生成及效验报文

组件接口

hmac_sha1.gs

函数原型函数作用
string create_secret_key(int length = 32)* 生成密钥,密钥默认长度32
buffer generate_hmac_sha1(string key, string msg)* 生成HMACSHA1效验码
bool check_msg(string key, string msg, buffer valid_code)* 通过密钥key与效验码valid_code效验码效验报文

简易示例

import pkg.hmac_sha1;

void test_hmac_sha1()
{
string comm_msg = "abcdefg123456";
string key = hmac_sha1.create_secret_key();
write("Secret key:", key,"\n");
buffer valid_code = hmac_sha1.generate_hmac_sha1(key, comm_msg);
write("Message valid code:",valid_code,"\n");
string tamper_msg = "abcdefg123455";
write("Check should be true here : ",hmac_sha1.check_msg(key, comm_msg, valid_code),"\n");
write("Check should be false here : ",hmac_sha1.check_msg(key, tamper_msg, valid_code),"\n");
}
test_hmac_sha1();