请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

stbrumme/hash-library: Portable C++ hashing library

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

stbrumme/hash-library

开源软件地址(OpenSource Url):

https://github.com/stbrumme/hash-library

开源编程语言(OpenSource Language):

C++ 100.0%

开源软件介绍(OpenSource Introduction):

Portable C++ Hashing Library

This is a mirror of my library hosted at https://create.stephan-brumme.com/hash-library/

In a nutshell:

  • computes CRC32, MD5, SHA1 and SHA256 (most common member of the SHA2 functions), Keccak and its SHA3 sibling
  • optional HMAC (keyed-hash message authentication code)
  • no external dependencies, small code size
  • can work chunk-wise (for example when reading streams block-by-block)
  • portable: supports Windows and Linux, tested on Little Endian and Big Endian CPUs
  • roughly as fast as Linux core hashing functions
  • open source, zlib license

You can find code examples, benchmarks and much more on my website https://create.stephan-brumme.com/hash-library/

How to use

This example computes SHA256 hashes but the API is more or less identical for all hash algorithms:

// SHA2 test program
#include "sha256.h"
#include <iostream> // for std::cout only, not needed for hashing library

int main(int, char**)
{
  // create a new hashing object
  SHA256 sha256;

  // hashing an std::string
  std::cout << sha256("Hello World") << std::endl;
  // => a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

  // hashing a buffer of bytes
  const char* buffer = "How are you";
  std::cout << sha256(buffer, 11) << std::endl;
  // => 9c7d5b046878838da72e40ceb3179580958df544b240869b80d0275cc07209cc

  // or in a streaming fashion (re-use "How are you")
  SHA256 sha256stream;
  const char* url = "create.stephan-brumme.com"; // 25 bytes
  int step = 5;
  for (int i = 0; i < 25; i += step)
    sha256stream.add(url + i, step); // add five bytes at a time
  std::cout << sha256stream.getHash() << std::endl;
  // => 82aa771f1183c52f973c798c9243a1c73833ea40961c73e55e12430ec77b69f6

  return 0;
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap