Merge pull request #85 from yogsototh/master

Example of symmetric encryption in documentation.
This commit is contained in:
Vincent Hanquez 2016-07-30 07:10:56 +01:00 committed by GitHub
commit d6608ffc6e
2 changed files with 37 additions and 0 deletions

34
Crypto/Tutorial.hs Normal file
View File

@ -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

View File

@ -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 <vincent@snarc.org>
@ -139,6 +141,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