From 92531e8ca6afb4224aa6744ab835929dc74da1f6 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Thu, 28 Apr 2016 00:26:45 +0200 Subject: [PATCH] Just adding an example. Inspired by the Turtle doc --- Crypto/Tutorial.hs | 34 ++++++++++++++++++++++++++++++++++ cryptonite.cabal | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 Crypto/Tutorial.hs diff --git a/Crypto/Tutorial.hs b/Crypto/Tutorial.hs new file mode 100644 index 0000000..83487c7 --- /dev/null +++ b/Crypto/Tutorial.hs @@ -0,0 +1,34 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} +{-# LANGUAGE OverloadedStrings #-} + +{-| How to use @cryptonite@ + +> -- | Beware MUST BE 256bits as we use AES256 +> import Data.ByteString (ByteString) +> import Crypto.Cipher.AES (AES256) +> import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),nullIV) +> import Crypto.Error (CryptoFailable(..)) +> +> secretKey :: ByteString +> secretKey = "012-456-89A-CDE-012-456-89A-CDE-" +> +> encrypt :: ByteString -> ByteString -> ByteString +> encrypt secret = ctrCombine ctx nullIV +> where +> ctx = cipherInitNoErr (cipherMakeKey (undefined :: AES256) secret) +> cipherInitNoErr :: BlockCipher c => Key c -> c +> cipherInitNoErr (Key k) = case cipherInit k of +> CryptoPassed a -> a +> CryptoFailed e -> error (show e) +> cipherMakeKey :: Cipher cipher => cipher -> ByteString -> Key cipher +> cipherMakeKey _ = Key -- Yeah Lazyness!!!!!! +> +> +> decrypt :: ByteString -> ByteString -> ByteString +> decrypt = encrypt + +|-} + +module Crypto.Tutorial () where + +import Crypto.Cipher.Types diff --git a/cryptonite.cabal b/cryptonite.cabal index 9d5a343..252eaa7 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -23,6 +23,8 @@ Description: cryptographic kitchen sink that provides cryptography for everyone. . Evaluate the security related to your requirements before using. + . + Read "Crypto.Tutorial" for a quick start guide. License: BSD3 License-file: LICENSE Copyright: Vincent Hanquez @@ -138,6 +140,7 @@ Library Crypto.Random.Entropy Crypto.Random.EntropyPool Crypto.Random.Entropy.Unsafe + Crypto.Tutorial Other-modules: Crypto.Cipher.AES.Primitive Crypto.Cipher.Blowfish.Box Crypto.Cipher.Blowfish.Primitive