License | BSD-style |
---|---|
Maintainer | Olivier Chéron <olivier.cheron@gmail.com> |
Stability | experimental |
Portability | unknown |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Password-Based Cryptography, aka PKCS #5.
Synopsis
- data ProtectionPassword
- emptyNotTerminated :: ProtectionPassword
- fromProtectionPassword :: ProtectionPassword -> ByteString
- toProtectionPassword :: ByteString -> ProtectionPassword
- type EncryptedContent = ByteString
- data PKCS5 = PKCS5 {}
- encrypt :: EncryptionScheme -> ProtectionPassword -> ByteString -> Either StoreError PKCS5
- decrypt :: PKCS5 -> ProtectionPassword -> Either StoreError ByteString
- data EncryptionScheme
- data PBEParameter = PBEParameter {
- pbeSalt :: Salt
- pbeIterationCount :: Int
- data PBES2Parameter = PBES2Parameter {}
- data KeyDerivationFunc
- data PBKDF2_PRF
- type Salt = ByteString
- generateSalt :: MonadRandom m => Int -> m Salt
- data ContentEncryptionParams
- data ContentEncryptionAlg
- = forall c.BlockCipher c => ECB (ContentEncryptionCipher c)
- | forall c.BlockCipher c => CBC (ContentEncryptionCipher c)
- | CBC_RC2
- | forall c.BlockCipher c => CFB (ContentEncryptionCipher c)
- | forall c.BlockCipher c => CTR (ContentEncryptionCipher c)
- data ContentEncryptionCipher cipher where
- DES :: ContentEncryptionCipher DES
- DES_EDE2 :: ContentEncryptionCipher DES_EDE2
- DES_EDE3 :: ContentEncryptionCipher DES_EDE3
- AES128 :: ContentEncryptionCipher AES128
- AES192 :: ContentEncryptionCipher AES192
- AES256 :: ContentEncryptionCipher AES256
- CAST5 :: ContentEncryptionCipher CAST5
- Camellia128 :: ContentEncryptionCipher Camellia128
- generateEncryptionParams :: MonadRandom m => ContentEncryptionAlg -> m ContentEncryptionParams
- getContentEncryptionAlg :: ContentEncryptionParams -> ContentEncryptionAlg
- pbEncrypt :: EncryptionScheme -> ByteString -> ProtectionPassword -> Either StoreError EncryptedContent
- pbDecrypt :: EncryptionScheme -> EncryptedContent -> ProtectionPassword -> Either StoreError ByteString
Documentation
data ProtectionPassword Source #
A password stored as a sequence of UTF-8 bytes.
Some key-derivation functions add restrictions to what characters are supported.
The data type provides a special value emptyNotTerminated
that is used
as alternate representation of empty passwords on some systems and that
produces encryption results different than an empty bytearray.
Conversion to/from a regular sequence of bytes is possible with functions
toProtectionPassword
and fromProtectionPassword
.
Beware: the fromString
implementation correctly handles multi-byte
characters, so here is not equivalent to the ByteString
counterpart.
Instances
IsString ProtectionPassword Source # | |
Defined in Crypto.Store.PKCS5.PBES1 fromString :: String -> ProtectionPassword # | |
Show ProtectionPassword Source # | |
Defined in Crypto.Store.PKCS5.PBES1 showsPrec :: Int -> ProtectionPassword -> ShowS # show :: ProtectionPassword -> String # showList :: [ProtectionPassword] -> ShowS # | |
Eq ProtectionPassword Source # | |
Defined in Crypto.Store.PKCS5.PBES1 (==) :: ProtectionPassword -> ProtectionPassword -> Bool # (/=) :: ProtectionPassword -> ProtectionPassword -> Bool # | |
ByteArrayAccess ProtectionPassword Source # | |
Defined in Crypto.Store.PKCS5.PBES1 length :: ProtectionPassword -> Int Source # withByteArray :: ProtectionPassword -> (Ptr p -> IO a) -> IO a Source # copyByteArrayToPtr :: ProtectionPassword -> Ptr p -> IO () Source # |
emptyNotTerminated :: ProtectionPassword Source #
A value denoting an empty password, but having a special encoding when deriving a symmetric key on some systems, like the certificate export wizard on Windows.
This value is different from
and can be tried
when decrypting content with a password known to be empty.toProtectionPassword
""
fromProtectionPassword :: ProtectionPassword -> ByteString Source #
Extract the UTF-8 bytes in a password value.
toProtectionPassword :: ByteString -> ProtectionPassword Source #
Build a password value from a sequence of UTF-8 bytes.
When the password is empty, the special value emptyNotTerminated
may
be tried as well.
type EncryptedContent = ByteString Source #
Encrypted content.
High-level API
Content encrypted with a Password-Based Encryption Scheme (PBES).
The content will usually be the binary representation of an ASN.1 object, however the transformation may be applied to any bytestring.
PKCS5 | |
|
encrypt :: EncryptionScheme -> ProtectionPassword -> ByteString -> Either StoreError PKCS5 Source #
Encrypt a bytestring with the specified encryption scheme and password.
decrypt :: PKCS5 -> ProtectionPassword -> Either StoreError ByteString Source #
Decrypt the PKCS #5 content with the specified password.
Encryption schemes
data EncryptionScheme Source #
Password-Based Encryption Scheme (PBES).
PBES2 PBES2Parameter | PBES2 |
PBE_MD5_DES_CBC PBEParameter | pbeWithMD5AndDES-CBC |
PBE_SHA1_DES_CBC PBEParameter | pbeWithSHA1AndDES-CBC |
PBE_SHA1_RC4_128 PBEParameter | pbeWithSHAAnd128BitRC4 |
PBE_SHA1_RC4_40 PBEParameter | pbeWithSHAAnd40BitRC4 |
PBE_SHA1_DES_EDE3_CBC PBEParameter | pbeWithSHAAnd3-KeyTripleDES-CBC |
PBE_SHA1_DES_EDE2_CBC PBEParameter | pbeWithSHAAnd2-KeyTripleDES-CBC |
PBE_SHA1_RC2_128 PBEParameter | pbeWithSHAAnd128BitRC2-CBC |
PBE_SHA1_RC2_40 PBEParameter | pbewithSHAAnd40BitRC2-CBC |
Instances
Show EncryptionScheme Source # | |
Defined in Crypto.Store.PKCS5 showsPrec :: Int -> EncryptionScheme -> ShowS # show :: EncryptionScheme -> String # showList :: [EncryptionScheme] -> ShowS # | |
Eq EncryptionScheme Source # | |
Defined in Crypto.Store.PKCS5 (==) :: EncryptionScheme -> EncryptionScheme -> Bool # (/=) :: EncryptionScheme -> EncryptionScheme -> Bool # |
data PBEParameter Source #
PBES1 parameters.
PBEParameter | |
|
Instances
Show PBEParameter Source # | |
Defined in Crypto.Store.PKCS5.PBES1 showsPrec :: Int -> PBEParameter -> ShowS # show :: PBEParameter -> String # showList :: [PBEParameter] -> ShowS # | |
Eq PBEParameter Source # | |
Defined in Crypto.Store.PKCS5.PBES1 (==) :: PBEParameter -> PBEParameter -> Bool # (/=) :: PBEParameter -> PBEParameter -> Bool # |
data PBES2Parameter Source #
PBES2 parameters.
PBES2Parameter | |
|
Instances
Show PBES2Parameter Source # | |
Defined in Crypto.Store.PKCS5 showsPrec :: Int -> PBES2Parameter -> ShowS # show :: PBES2Parameter -> String # showList :: [PBES2Parameter] -> ShowS # | |
Eq PBES2Parameter Source # | |
Defined in Crypto.Store.PKCS5 (==) :: PBES2Parameter -> PBES2Parameter -> Bool # (/=) :: PBES2Parameter -> PBES2Parameter -> Bool # |
Key derivation
data KeyDerivationFunc Source #
Key derivation algorithm and associated parameters.
PBKDF2 | Key derivation with PBKDF2 |
| |
Scrypt | Key derivation with Scrypt |
Instances
Show KeyDerivationFunc Source # | |
Defined in Crypto.Store.CMS.Algorithms showsPrec :: Int -> KeyDerivationFunc -> ShowS # show :: KeyDerivationFunc -> String # showList :: [KeyDerivationFunc] -> ShowS # | |
Eq KeyDerivationFunc Source # | |
Defined in Crypto.Store.CMS.Algorithms (==) :: KeyDerivationFunc -> KeyDerivationFunc -> Bool # (/=) :: KeyDerivationFunc -> KeyDerivationFunc -> Bool # |
data PBKDF2_PRF Source #
Pseudorandom function used for PBKDF2.
PBKDF2_SHA1 | hmacWithSHA1 |
PBKDF2_SHA256 | hmacWithSHA256 |
PBKDF2_SHA512 | hmacWithSHA512 |
Instances
OIDNameable PBKDF2_PRF Source # | |
Defined in Crypto.Store.CMS.Algorithms fromObjectID :: OID -> Maybe PBKDF2_PRF Source # | |
OIDable PBKDF2_PRF Source # | |
Defined in Crypto.Store.CMS.Algorithms getObjectID :: PBKDF2_PRF -> OID Source # | |
Show PBKDF2_PRF Source # | |
Defined in Crypto.Store.CMS.Algorithms showsPrec :: Int -> PBKDF2_PRF -> ShowS # show :: PBKDF2_PRF -> String # showList :: [PBKDF2_PRF] -> ShowS # | |
Eq PBKDF2_PRF Source # | |
Defined in Crypto.Store.CMS.Algorithms (==) :: PBKDF2_PRF -> PBKDF2_PRF -> Bool # (/=) :: PBKDF2_PRF -> PBKDF2_PRF -> Bool # |
type Salt = ByteString Source #
Salt value used for key derivation.
generateSalt :: MonadRandom m => Int -> m Salt Source #
Generate a random salt with the specified length in bytes. To be most effective, the length should be at least 8 bytes.
Content encryption
data ContentEncryptionParams Source #
Content encryption algorithm with associated parameters (i.e. the initialization vector).
A value can be generated with generateEncryptionParams
.
Instances
Show ContentEncryptionParams Source # | |
Defined in Crypto.Store.CMS.Algorithms showsPrec :: Int -> ContentEncryptionParams -> ShowS # show :: ContentEncryptionParams -> String # showList :: [ContentEncryptionParams] -> ShowS # | |
HasKeySize ContentEncryptionParams Source # | |
Eq ContentEncryptionParams Source # | |
Defined in Crypto.Store.CMS.Algorithms |
data ContentEncryptionAlg Source #
Cipher and mode of operation for content encryption.
forall c.BlockCipher c => ECB (ContentEncryptionCipher c) | Electronic Codebook |
forall c.BlockCipher c => CBC (ContentEncryptionCipher c) | Cipher Block Chaining |
CBC_RC2 | RC2 in CBC mode |
forall c.BlockCipher c => CFB (ContentEncryptionCipher c) | Cipher Feedback |
forall c.BlockCipher c => CTR (ContentEncryptionCipher c) | Counter |
Instances
OIDNameable ContentEncryptionAlg Source # | |
Defined in Crypto.Store.CMS.Algorithms | |
OIDable ContentEncryptionAlg Source # | |
Defined in Crypto.Store.CMS.Algorithms | |
Show ContentEncryptionAlg Source # | |
Defined in Crypto.Store.CMS.Algorithms showsPrec :: Int -> ContentEncryptionAlg -> ShowS # show :: ContentEncryptionAlg -> String # showList :: [ContentEncryptionAlg] -> ShowS # |
data ContentEncryptionCipher cipher where Source #
CMS content encryption cipher.
DES :: ContentEncryptionCipher DES | DES |
DES_EDE2 :: ContentEncryptionCipher DES_EDE2 | Triple-DES with 2 keys used in alternative direction |
DES_EDE3 :: ContentEncryptionCipher DES_EDE3 | Triple-DES with 3 keys used in alternative direction |
AES128 :: ContentEncryptionCipher AES128 | AES with 128-bit key |
AES192 :: ContentEncryptionCipher AES192 | AES with 192-bit key |
AES256 :: ContentEncryptionCipher AES256 | AES with 256-bit key |
CAST5 :: ContentEncryptionCipher CAST5 | CAST5 (aka CAST-128) with key between 40 and 128 bits |
Camellia128 :: ContentEncryptionCipher Camellia128 | Camellia with 128-bit key |
Instances
Show (ContentEncryptionCipher cipher) Source # | |
Defined in Crypto.Store.CMS.Algorithms showsPrec :: Int -> ContentEncryptionCipher cipher -> ShowS # show :: ContentEncryptionCipher cipher -> String # showList :: [ContentEncryptionCipher cipher] -> ShowS # | |
Eq (ContentEncryptionCipher cipher) Source # | |
Defined in Crypto.Store.CMS.Algorithms (==) :: ContentEncryptionCipher cipher -> ContentEncryptionCipher cipher -> Bool # (/=) :: ContentEncryptionCipher cipher -> ContentEncryptionCipher cipher -> Bool # |
generateEncryptionParams :: MonadRandom m => ContentEncryptionAlg -> m ContentEncryptionParams Source #
Generate random parameters for the specified content encryption algorithm.
getContentEncryptionAlg :: ContentEncryptionParams -> ContentEncryptionAlg Source #
Get the content encryption algorithm.
Low-level API
pbEncrypt :: EncryptionScheme -> ByteString -> ProtectionPassword -> Either StoreError EncryptedContent Source #
Encrypt a bytestring with the specified encryption scheme and password.
pbDecrypt :: EncryptionScheme -> EncryptedContent -> ProtectionPassword -> Either StoreError ByteString Source #
Decrypt an encrypted bytestring with the specified encryption scheme and password.