Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

PicoSHA2

> 编程语言
Open source

a header-file-only, SHA256 hash generator in C++

753 stars0 likes1 views
WebsiteGitHub

About

a header-file-only, SHA256 hash generator in C++

PicoSHA2 - a C++ SHA256 hash generator

Copyright © 2017 okdshin

Introduction

PicoSHA2 is a tiny SHA256 hash generator for C++ with following properties:

  • header-file only
  • no external dependencies (only uses standard C++ libraries)
  • STL-friendly
  • licensed under MIT License

Generating SHA256 hash and hash hex string

cpp
// any STL sequantial container (vector, list, dequeue...)
std::string src_str = "The quick brown fox jumps over the lazy dog";

std::vector hash(picosha2::k_digest_size);
picosha2::hash256(src_str.begin(), src_str.end(), hash.begin(), hash.end());

std::string hex_str = picosha2::bytes_to_hex_string(hash.begin(), hash.end());

Generating SHA256 hash and hash hex string from byte stream

cpp
picosha2::hash256_one_by_one hasher;
...
hasher.process(block.begin(), block.end());
...
hasher.finish();

std::vector hash(picosha2::k_digest_size);
hasher.get_hash_bytes(hash.begin(), hash.end());

std::string hex_str = picosha2::get_hash_hex_string(hasher);

The file example/interactive_hasher.cpp has more detailed information.

Generating SHA256 hash from a binary file

cpp
std::ifstream f("file.txt", std::ios::binary);
std::vector s(picosha2::k_digest_size);
picosha2::hash256(f, s.begin(), s.end());

This hash256 may use less memory than reading whole of the file.

Generating SHA256 hash hex string from std::string

cpp
std::string src_str = "The quick brown fox jumps over the lazy dog";
std::string hash_hex_str;
picosha2::hash256_hex_string(src_str, hash_hex_str);
std::cout  src_vect(...);
std::string hash_hex_str;
picosha2::hash256_hex_string(src_vect, hash_hex_str);
cpp
std::vector src_vect(...);
std::string hash_hex_str = picosha2::hash256_hex_string(src_vect);
cpp
unsigned char src_c_array[picosha2::k_digest_size] = {...};
std::string hash_hex_str;
picosha2::hash256_hex_string(src_c_array, src_c_array+picosha2::k_digest_size, hash_hex_str);
cpp
unsigned char src_c_array[picosha2::k_digest_size] = {...};
std::string hash_hex_str = picosha2::hash256_hex_string(src_c_array, src_c_array+picosha2::k_digest_size);

Generating SHA256 hash byte sequence from STL sequential container

cpp
//any STL sequantial container (vector, list, dequeue...)
std::string src_str = "The quick brown fox jumps over the lazy dog";

//any STL sequantial containers (vector, list, dequeue...)
std::vector hash(picosha2::k_digest_size);

// in: container, out: container
picosha2::hash256(src_str, hash);
cpp
//any STL sequantial container (vector, list, dequeue...)
std::string src_str = "The quick brown fox jumps over the lazy dog";

//any STL sequantial containers (vector, list, dequeue...)
std::vector hash(picosha2::k_digest_size);

// in: iterator pair, out: contaner
picosha2::hash256(src_str.begin(), src_str.end(), hash);
cpp
std::string src_str = "The quick brown fox jumps over the lazy dog";
unsigned char hash_byte_c_array[picosha2::k_digest_size];
// in: container, out: iterator(pointer) pair
picosha2::hash256(src_str, hash_byte_c_array, hash_byte_c_array+picosha2::k_digest_size);
cpp
std::string src_str = "The quick brown fox jumps over the lazy dog";
std::vector hash(picosha2::k_digest_size);
// in: iterator pair, out: iterator pair
picosha2::hash256(src_str.begin(), src_str.end(), hash.begin(), hash.end());

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++cppcpp-libraryheader-onlymit-license

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言