File: Tutorial.hs

package info (click to toggle)
haskell-cryptonite 0.20-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,936 kB
  • ctags: 1,963
  • sloc: ansic: 31,728; haskell: 10,183; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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