View Source ecies (ecies v1.1.0)
This module contains functions for generating EC keys and encrypting, decrypting data using Elliptic Curve Integrated Encryption Scheme (ECIES).
Summary
Functions
Default elliptic curve secp256k1
and set of algorithms used for ECIES encryption/decryption.
Equivalent to generate_key(default_params()).
Params
under curve
key.Equivalent to private_decrypt(PrivateKey, CipherData, default_params()).
Decrypts the CipherData
using the PrivateKey
and returns the PlainText
Equivalent to public_encrypt(OthersPublicKey, PlainText, default_params()).
Encrypts the PlainText
using the OthersPublicKey
and returns encrypted data (binary cipher text by default).
ecies
libraryTypes
-type aead_cipher() ::
aes_ccm | aes_gcm | aes_128_ccm | aes_128_gcm | aes_192_ccm | aes_192_gcm | aes_256_ccm |
aes_256_gcm | chacha20_poly1305.
-type auth_tag() :: binary().
-type cipher() :: 'xor' | atom().
-type cipher_text() :: binary().
-type cmac_cipher() :: aes_cbc | aes_128_cbc | aes_192_cbc | aes_256_cbc.
-type digest_type() ::
sha | sha224 | sha256 | sha384 | sha512 | sha3_224 | sha3_256 | sha3_384 | sha3_512 |
ripemd160 | blake2b | blake2s | md5 | md4 | sm3.
-type ecies_params() :: #{curve := named_curve(), compress_pubkey => boolean(), cipher => cipher(), kdf => kdf_type(), mac => mac_type(), s1 => binary(), s2 => binary(), key => keypair(), iv => binary() | random | fun(), embedded_iv => boolean(), generate_key => fun(), shared_key => binary() | fun(), derive_keys => fun(), prepare_payload => fun(), decode => fun(), encode => as_tuple | raw | fun(), others_public_key => public_key(), _ => _}.
-type encrypted_data() :: binary() | {public_key(), cipher_text(), MAC :: auth_tag()}.
-type kdf_fun() :: fun((SharedKey :: binary(), Info :: binary(), Length :: pos_integer()) -> Result :: binary()).
-type kdf_type() :: {hkdf, digest_type()} | {kdf, digest_type()} | {concat_kdf, digest_type()} | kdf_fun().
-type keypair() :: {public_key(), private_key()}.
-type mac_bits() :: pos_integer() | default.
-type mac_type() :: {hmac, digest_type(), mac_bits()} | {cmac, cmac_cipher(), mac_bits()} | {aead, mac_bits()}.
-type named_curve() :: crypto:ec_named_curve() | x25519 | x448.
-type plain_text() :: iodata().
-type private_key() :: binary().
-type public_key() :: binary().
Functions
-spec default_params() -> ecies_params().
Default elliptic curve secp256k1
and set of algorithms used for ECIES encryption/decryption.
-spec generate_key() -> keypair().
Equivalent to generate_key(default_params()).
Generates a new key pair for defaultsecp256k1
curve
-spec generate_key(#{curve := named_curve(), _ => _}) -> keypair().
Params
under curve
key.
-spec private_decrypt(private_key(), encrypted_data()) -> binary().
Equivalent to private_decrypt(PrivateKey, CipherData, default_params()).
Decrypts the CipherData
using the PrivateKey
and returns the PlainText
secp256k1
and other params returned from default_params/0
-spec private_decrypt(private_key(), encrypted_data(), ecies_params()) -> binary() | error.
Decrypts the CipherData
using the PrivateKey
and returns the PlainText
Params
argument
-spec public_encrypt(OthersPublicKey :: public_key(), PlainText :: plain_text()) -> CipherText :: binary().
Equivalent to public_encrypt(OthersPublicKey, PlainText, default_params()).
Encrypts the PlainText
using the OthersPublicKey
and returns the CipherText
secp256k1
and other params returned from default_params/0
-spec public_encrypt(OthersPublicKey :: public_key(), plain_text(), ecies_params()) -> encrypted_data().
Encrypts the PlainText
using the OthersPublicKey
and returns encrypted data (binary cipher text by default).
Params
argument
-spec supports(hashs) -> [digest_type()]; (curves) -> [named_curve()]; (ciphers) -> [cipher()]; (cmac_ciphers) -> [cmac_cipher()]; (aead_ciphers) -> [aead_cipher()].
ecies
library