Unauthenticated AES encryption as a service (Effect's
effect/crypto/Cipher)::
cipher = yield from Cipher()
encrypted = yield from cipher.encrypt(key, data, iv=iv)AES-CTR counts with the whole 128-bit block and never fails to decrypt;
AES-CBC pads with PKCS#7 and fails every bad padding or length with the
same DecryptionFailed (distinguishable failures would be a padding
oracle). Prefer aead: nothing here detects tampering.
Re-exports#
Values#
| Attribute | Type | Description |
|---|---|---|
aes128_ctr | Algorithm | |
aes256_ctr | Algorithm | |
aes128_cbc | Algorithm | |
aes256_cbc | Algorithm | |
layer_web_crypto | Layer[Cipher, Never, SecureRandom] | AES-CTR and AES-CBC on the |
Classes#
Functions#
is_key#
is_key(u) -> bool| Parameter | Type | Description |
|---|---|---|
u | object |
Returns bool
def is_key(u: object) -> bool:
return isinstance(u, Key)key#
key[A: Algorithm](algorithm, data) -> Effect[Key[A], CryptoError]A key holding a copy of data, which must be the algorithm's key
length.
| Parameter | Type | Description |
|---|---|---|
algorithm | A | |
data | Binary |
Returns Effect[Key[A], CryptoError]
def key[A: Algorithm](algorithm: A, data: Binary) -> Effect[Key[A], CryptoError]:
"""A key holding a copy of ``data``, which must be the algorithm's key
length."""
return _key.from_bytes(
lambda copied: Key(algorithm, copied),
"Cipher",
"key",
data,
_key.check_key_length(algorithm.name, algorithm.key_length),
)from_crypto_key#
from_crypto_key[A: Algorithm](algorithm, crypto_key) -> Effect[Key[A], CryptoError]A key backed by a CryptoKey of the algorithm's mode and size,
with both the encrypt and decrypt usages.
| Parameter | Type | Description |
|---|---|---|
algorithm | A | |
crypto_key | CryptoKey |
Returns Effect[Key[A], CryptoError]
def from_crypto_key[A: Algorithm](
algorithm: A, crypto_key: CryptoKey
) -> Effect[Key[A], CryptoError]:
"""A key backed by a ``CryptoKey`` of the algorithm's mode and size,
with both the ``encrypt`` and ``decrypt`` usages."""
return _key.from_crypto_key(
Key,
"Cipher",
"fromCryptoKey",
algorithm,
crypto_key,
_key.ExpectedCryptoKey(
type="secret",
name=algorithm.mode,
usages=("encrypt", "decrypt"),
usage_policy="all",
check=_key.check_aes_length(algorithm.mode, algorithm.key_length),
),
)to_bytes#
to_bytes(key) -> Effect[bytes, CryptoError]A copy of the key's bytes; NotExtractable for a non-extractable
CryptoKey.
| Parameter | Type | Description |
|---|---|---|
key | Key[Any] |
Returns Effect[bytes, CryptoError]
def to_bytes(key: Key[Any]) -> Effect[bytes, CryptoError]:
"""A copy of the key's bytes; ``NotExtractable`` for a non-extractable
``CryptoKey``."""
return _key.to_bytes("Cipher", key, _key.export_raw)