Adbase
Adinf C++ base library V2
adbase::Sha1 Class Reference

实现 SHA1 算法 More...

#include <Sha1.hpp>

Public Member Functions

 Sha1 ()
 
void update (const std::string &s)
 给定一个需要编码的字符串 More...
 
void update (std::istream &is)
 给定一个需要编码的字符串 More...
 
std::string final ()
 获取最终编码的字符串 More...
 
void final (char *result)
 获取最终编码的字符串 More...
 

Static Public Member Functions

static std::string from_file (const std::string &filename)
 直接给定文件进行 sha1 编码 More...
 
static void hmacSha1 (const char *key, size_t keylen, const char *msg, size_t msglen, char *out)
 

Detailed Description

实现 SHA1 算法

Example
const string input = "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
adbase::Sha1 checksum;
checksum.update(input);
std::string hash = checksum.final();

Definition at line 30 of file Sha1.hpp.

Constructor & Destructor Documentation

adbase::Sha1::Sha1 ( )

Definition at line 214 of file Sha1.cpp.

References adbase::detail::reset().

Member Function Documentation

std::string adbase::Sha1::final ( )

获取最终编码的字符串

Returns
最终编码的字符串
Exceptions
none
Example
const string input = "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
adbase::Sha1 checksum;
checksum.update(input);
std::string hash = checksum.final();

Definition at line 250 of file Sha1.cpp.

References adbase::detail::BLOCK_BYTES, adbase::detail::BLOCK_INTS, adbase::detail::buffer_to_block(), adbase::detail::reset(), and adbase::detail::transform().

Referenced by hmacSha1().

void adbase::Sha1::final ( char *  result)

获取最终编码的字符串

Parameters
result返回编码的结果(raw)
Returns
void
Exceptions
none
Example
const string input = "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
adbase::Sha1 checksum;
checksum.update(input);
char hash[20] = {0};
checksum.final(hash);

Definition at line 295 of file Sha1.cpp.

References adbase::detail::BLOCK_BYTES, adbase::detail::BLOCK_INTS, adbase::detail::buffer_to_block(), adbase::detail::reset(), and adbase::detail::transform().

std::string adbase::Sha1::from_file ( const std::string &  filename)
static

直接给定文件进行 sha1 编码

Returns
最终编码的字符串
Exceptions
none
Example
std::string filename = 'test.txt';
std::string hash = adbase::Sha1::from_file(filename);

Definition at line 337 of file Sha1.cpp.

References update().

void adbase::Sha1::hmacSha1 ( const char *  key,
size_t  keylen,
const char *  msg,
size_t  msglen,
char *  out 
)
static

Definition at line 347 of file Sha1.cpp.

References final(), and update().

void adbase::Sha1::update ( const std::string &  s)

给定一个需要编码的字符串

Example
const string input = "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
adbase::Sha1 checksum;
checksum.update(input);
std::string hash = checksum.final();

Definition at line 221 of file Sha1.cpp.

Referenced by from_file(), and hmacSha1().

void adbase::Sha1::update ( std::istream &  is)

给定一个需要编码的字符串

Example
std::ifstream stream(filename.c_str(), std::ios::binary);
Sha1 checksum;
checksum.update(stream);
std::string hash = checksum.final();

Definition at line 229 of file Sha1.cpp.

References adbase::detail::BLOCK_BYTES, adbase::detail::BLOCK_INTS, adbase::detail::buffer_to_block(), and adbase::detail::transform().


The documentation for this class was generated from the following files: