mateamt/src/Util/Crypto.hs

16 lines
505 B
Haskell
Raw Normal View History

2022-04-17 11:47:46 +00:00
module Util.Crypto where
import Crypto.KDF.Argon2
import Crypto.Error (CryptoFailable)
import qualified Data.ByteString as BS
2022-04-17 14:38:48 +00:00
import Data.ByteString.Base64
2022-04-17 11:47:46 +00:00
2022-04-30 08:10:26 +00:00
import System.Random.Stateful (uniformByteStringM, newIOGenM, initStdGen)
2022-04-17 11:47:46 +00:00
randomString :: IO BS.ByteString
2022-04-30 08:10:26 +00:00
randomString = encode <$> (uniformByteStringM 32 =<< newIOGenM =<< initStdGen)
2022-04-17 11:47:46 +00:00
argon2 :: BS.ByteString -> BS.ByteString -> CryptoFailable BS.ByteString
2022-04-17 14:38:48 +00:00
argon2 salt payload = encode <$> hash defaultOptions payload (decodeLenient salt) 64