vid*_*idi 2 haskell cryptography
我需要来自cryptonite的 Scrypt,AES256和RSA ,我很难弄清楚如何使用它们.这些有一些很好的例子吗?
本教程不完整,并不重要.
谢谢!
PS:我既不是密码学也不是Haskell专家.
试图发布一个更好的问题,我设法编译代码.我发布了我的解决方案,希望它可以帮助别人
import Crypto.Random(getSystemDRG, randomBytesGenerate)
import Crypto.KDF.Scrypt (generate, Parameters(..))
import Crypto.Cipher.AES (AES256)
import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),nullIV)
import Crypto.Error (throwCryptoError)
saltSize = 32
paramN = 14 :: Word64
paramR = 8
paramP = 1
paramKeyLen = 32
-- AES256 encryption
encrypt :: ByteString -> ByteString -> ByteString
encrypt key plainData = ctrCombine ctx nullIV plainData
where ctx :: AES256
ctx = throwCryptoError $ cipherInit key
decrypt :: ByteString -> ByteString -> ByteString
decrypt = encrypt
--Scrypt KDF
deriveKey :: Text -> ByteString -> ByteString
deriveKey password salt = generate params (encodeUtf8 password) salt
where params = Parameters {n = paramN, r = paramR, p = paramP, outputLength = paramKeyLen}
-- for generating the salt
random :: Int -> IO ByteString
random size = do
drg <- getSystemDRG
let (bytes, _) = randomBytesGenerate size drg
return bytes
Run Code Online (Sandbox Code Playgroud)