Coder Social home page Coder Social logo

cpp_sha1's Introduction

C++ implementation of Secure Hash Algorithm 1 (SHA1)

Simple C++ SHA 1 implementation based on RFC-3174 document

Example

  1. With i/o streams

        HasherSHA h;
        std::cin >> h;
        std::cout << h;
  2. Pass string in constructor

        std::string testString = "abcde";
        HasherSHA h(testString);
        std::cout << h << std::endl;
  3. Pass string to 'hashString' method

         std::string testString = "abcde";
         HasherSHA h;
         h.hashString(testString);
         std::cout << h.getHashedString() << std::endl;
  4. Multiple rounds of hashing

        std::string testString = "abcde";
        HasherSHA h(testString);
    
        for(int i = 0; i < 5; i++) {
            h.hashString(h.getHashedString());
            std::cout << h << std::endl;
        }
    
  5. File hashing

       HasherSHA h;
       h.hashString(utils::readFileIntoString("test.txt"));
       std::cout << h << std::endl;

    or (if you do not want to use function from utils)

       HasherSHA h;
       std::ifstream file(filepath, std::ios::binary);
    
       std::string fileContent((std::istreambuf_iterator<char>(file)),
                               std::istreambuf_iterator<char>());
    
       h.hashString(fileContent);
       std::cout << h << std::endl;

Additional information

As long as you pass data to the Hasher as std::string it should be working fine

However, I have not check its work on something except simple strings

UPD 06.01.2020 : Files also can be easily hashed by reading them as binary data into std::string. I added example in main.cpp

Warning

You should not use SHA-1 unless you have to!

This algorithm is not secure anymore

cpp_sha1's People

Watchers

Cringengineer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.