16 lines
502 B
Haskell
16 lines
502 B
Haskell
module Util.Crypto where
|
|
|
|
import Crypto.KDF.Argon2
|
|
import Crypto.Error (CryptoFailable)
|
|
|
|
import qualified Data.ByteString as BS
|
|
import Data.ByteString.Base64
|
|
|
|
import System.Random.Stateful (uniformByteStringM, newIOGenM, mkStdGen)
|
|
|
|
randomString :: IO BS.ByteString
|
|
randomString = encode <$> (uniformByteStringM 32 =<< newIOGenM (mkStdGen 23))
|
|
|
|
argon2 :: BS.ByteString -> BS.ByteString -> CryptoFailable BS.ByteString
|
|
argon2 salt payload = encode <$> hash defaultOptions payload (decodeLenient salt) 64
|