Advanced EOS Series — Part 1 — Cryptographic Hashes

Mitch Pierias
Dec 2, 2018 · 4 min read

The Cryptographic Hash Function

Application of Hashes


Coding Our Hash Function

include <eosiolib/crypto.h>
checksum256 sum{};
sha256(const_cast<char*>(str.c_str()), str.size(), &sum);
printhex(&sum, sizeof(sum));

Taking it Further — Checksum to String

template <typename CharT>string to_hex(const CharT* data, uint32_t length) {
  // Method Body
}
string result;
const char* hex_chars = "0123456789abcdef";
uint8_t* c = (uint8_t*)data;
for (uint32_t i = 0; i < length; ++i) {
  (result += hex_chars[(c[i] >> 4)]) += hex_chars[(c[i] & 0x0f)];
}return result;

What’s next?

Click to read today’s top story

Coinmonks

Coinmonks is a technology-focused publication embracing decentralize technologies. We are Non-profit and education is our core value. Learn, Build and thrive. Our other project— https://coinmonks.com, https://cryptofi.co, https://coincodecap.com

321

321 claps
Mitch Pierias

Written by

Self educated Software Developer

Coinmonks

Coinmonks

Coinmonks is a technology-focused publication embracing decentralize technologies. We are Non-profit and education is our core value. Learn, Build and thrive. Our other project— https://coinmonks.com, https://cryptofi.co, https://coincodecap.com