Skip to content

hashSum

Abstract

Functions compatible with the hashSum commands.
ハッシュ値を計算するコマンドの互換関数です.

Header file

namespace sstd{
    std::string vecUint8_to_hexString(const std::vector<uint8>& hash);

    std::string md5sum   (const char*        pPath);
    std::string sha1sum  (const char*        pPath);
    std::string sha224sum(const char*        pPath);
    std::string sha256sum(const char*        pPath);
    std::string sha384sum(const char*        pPath);
    std::string sha512sum(const char*        pPath);

    std::string md5sum   (const std::string&  path);
    std::string sha1sum  (const std::string&  path);
    std::string sha224sum(const std::string&  path);
    std::string sha256sum(const std::string&  path);
    std::string sha384sum(const std::string&  path);
    std::string sha512sum(const std::string&  path);
}

Description

Function name Description
vecUint8_to_hexString() converts the input binary to to a hexadecimal string.
入力されたバイナリを,16 進数表記の文字列に変換します.
md5sum() returns the result of md5sum calculation as a string. And returns 0 length std::string object when the md5sum() function failed.
md5sum の計算結果を文字列で返します.関数が失敗した場合は,長さ 0 の std::string オブジェクトを返却します.
sha1sum() returns the result of sha1sum calculation as a string. And returns 0 length std::string object when the sha1sum() function failed.
sha1sum の計算結果を文字列で返します.関数が失敗した場合は,長さ 0 の std::string オブジェクトを返却します.
sha224sum() returns the result of sha224sum calculation as a string. And returns 0 length std::string object when the sha224sum() function failed.
sha224sum の計算結果を文字列で返します.関数が失敗した場合は,長さ 0 の std::string オブジェクトを返却します.
sha256sum() returns the result of sha256sum calculation as a string. And returns 0 length std::string object when the sha256sum() function failed.
sha256sum の計算結果を文字列で返します.関数が失敗した場合は,長さ 0 の std::string オブジェクトを返却します.
sha384sum() returns the result of sha384sum calculation as a string. And returns 0 length std::string object when the sha384sum() function failed.
sha384sum の計算結果を文字列で返します.関数が失敗した場合は,長さ 0 の std::string オブジェクトを返却します.
sha512sum() returns the result of sha512sum calculation as a string. And returns 0 length std::string object when the sha512sum() function failed.
sha512sum の計算結果を文字列で返します.関数が失敗した場合は,長さ 0 の std::string オブジェクトを返却します.

Usage

  • main.cpp
    #include <sstd/sstd.hpp>
    
    int main(){
        sstd::mkdir("./tmp");
        sstd::system("head -c 5m /dev/urandom > ./tmp/rand.bin"); // generate 5 MB random file
    
        sstd::printn( sstd::sha256sum("./tmp/rand.bin") );
    
        printf("\n");
        fflush(stdout);
        sstd::system("sha256sum ./tmp/rand.bin");
        sstd::rm("./tmp");
    }
    
  • Execution result
    sstd::sha256sum("./tmp/rand.bin") = "20317782dda0aae6b78a74f22e27e5f23feba3e9d87c3965e533f411cb21e348"
    
    20317782dda0aae6b78a74f22e27e5f23feba3e9d87c3965e533f411cb21e348  ./tmp/rand.bin
    

Implementation