Skip to content

Instantly share code, notes, and snippets.

@tippenein
Created October 7, 2016 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tippenein/582afd7e6bcee54e98b384d976af94e3 to your computer and use it in GitHub Desktop.
Save tippenein/582afd7e6bcee54e98b384d976af94e3 to your computer and use it in GitHub Desktop.
sha256 hash file(s) from command line
#!/usr/bin/env runhaskell
import Crypto.Hash
import Data.ByteString
import Prelude hiding (readFile)
import System.Environment (getArgs)
keyFor :: FilePath -> IO ()
keyFor filepath = do
bytes <- readFile filepath
print $ hexSha3_256 bytes
sha1 :: ByteString -> Digest SHA1
sha1 = hash
hexSha3_256 :: ByteString -> String
hexSha3_256 bs = show (hash bs :: Digest SHA3_256)
main :: IO ()
main = do
args <- getArgs
case args of
[] -> print "gimme filepath(s)"
[filepath] -> keyFor filepath
filepaths -> mapM_ keyFor filepaths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment