{"id":15056293,"url":"https://github.com/simplito/ecies-erl","last_synced_at":"2026-02-06T22:31:24.122Z","repository":{"id":251105262,"uuid":"836401628","full_name":"simplito/ecies-erl","owner":"simplito","description":"Customizable Erlang native ECIES public-key cryptography library","archived":false,"fork":false,"pushed_at":"2024-08-04T08:41:11.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-07T03:28:30.602Z","etag":null,"topics":["ecies","ecies-encryption","erlang"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplito.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-31T19:12:23.000Z","updated_at":"2024-12-08T19:14:20.000Z","dependencies_parsed_at":"2024-08-03T15:29:03.653Z","dependency_job_id":"f7db981e-5335-4625-b9d9-001b7069c6c1","html_url":"https://github.com/simplito/ecies-erl","commit_stats":null,"previous_names":["simplito/ecies-erl"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/simplito/ecies-erl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fecies-erl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fecies-erl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fecies-erl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fecies-erl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplito","download_url":"https://codeload.github.com/simplito/ecies-erl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fecies-erl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29179415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T22:12:24.066Z","status":"ssl_error","status_checked_at":"2026-02-06T22:12:09.859Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecies","ecies-encryption","erlang"],"created_at":"2024-09-24T21:49:46.434Z","updated_at":"2026-02-06T22:31:24.106Z","avatar_url":"https://github.com/simplito.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build and Test](https://github.com/simplito/ecies-erl/actions/workflows/erlang.yml/badge.svg)](https://github.com/simplito/ecies-erl/actions/workflows/erlang.yml)\n[![Hex](https://img.shields.io/hexpm/v/ecies.svg)](https://hex.pm/packages/ecies)\n\nCustomizable Erlang native ECIES public-key cryptography library\n================================================================\n\nAn Erlang native library implementing the ECIES (Elliptic Curve Integrated Encryption Scheme) public-key cryptography, providing elliptic curve encryption as an alternative to the deprecated `crypto` `public_encrypt`, `private_decrypt` functions.\n\nMotivation\n----------\n\nThe Erlang OTP team decided to deprecate several `crypto` module functions in OTP 27 (See [functions deprecated in OTP 27](https://www.erlang.org/doc/deprecations.html#functions-deprecated-in-otp-27)).\nNotably, no alternatives were provided for two of them `crypto:public_encrypt/4` and `crypto:private_decrypt/4`.\n\nSome information about potential background of these deprecations can be found [here](https://erlangforums.com/t/security-working-group-minutes/3451/6).\n\nIt is worth mentioning that the above mentioned functions are RSA specific and cannot be used with Elliptic Curve cryptography anyway. \nIn our projects we mainly use Elliptic Curve cryptography and we decided to share this small library for ECIES with the Erlang developers community.  \n\nWe will be happy if you find it useful and use in your project. If you find any ideas for improvements or notice any missing functionality, please open an issue here; even better propose a Pull Request.\n\nUsage\n-----\n\nThe API of library is simple:\n- `ecies:generate_key/0`- can be used to generate public/private key pair\n- `ecies:public_encrypt/2` - for encrypting binary message with given public key\n- `ecies:private_decrypt/2` - for decrypting data using private key corresponding to public key used in `public_encrypt`\n\nExample: \n\n```erlang\n% Bob generates keys, and publish his public key\n{BobPublicKey, BobPrivateKey} = ecies:generate_key(),\n% Alice knowing Bob's public key encrypts a message for him\nData = ecies:public_encrypt(BobPublicKey, \u003c\u003c\"top secret message\"\u003e\u003e),\n% Bob is able to decrypt the message using his private key\n\u003c\u003c\"top secret message\"\u003e\u003e = ecies:private_decrypt(BobPrivateKey, Data).\n```\n\nIn the above example the default params are used (as returned by `ecies:default_params/0`):\n```erlang\n  #{\n    curve    =\u003e secp256k1,\n    cipher   =\u003e aes_256_cbc,\n    kdf      =\u003e {kdf, sha256},      % ANSI-X9.63 key derivation\n    mac      =\u003e {hmac, sha256, 256} % HMAC SHA256 with 256 bits (32 bytes) output\n  }.\n```\n\n#### Openssl interoperability\n\nYou can read or write keys in [PEM](https://datatracker.ietf.org/doc/html/rfc7468) format using function from `ecies_pem` module:\n\n- `ecies_pem:decode_public/1` - decodes a public key from the given \"PUBLIC KEY\" or \"EC PRIVATE KEY\" PEM format.\n- `ecies_pem:decode_private/1` - decodes a private key from the given \"EC PRIVATE KEY\" PEM format.\n- `ecies_pem:decode_keypair/1` - decodes both keys from the given \"EC PRIVATE KEY\" PEM format.\n- `ecies_pem:encode_public/1` - encodes a public key into \"PUBLIC KEY\" PEM format.\n- `ecies_pem:encode_private/1` - encodes a private key into \"EC PRIVATE KEY\" PEM format.\n- `ecies_pem:encode_keypair/1` - encodes both keys into \"EC PRIVATE KEY\" PEM format.\n\nExample:\n```shell\nopenssl ecparam -noout -genkey -conv_form compressed -name secp256k1 | tee private.pem\n```\n```erlang\n{ok, Pem} = file:read_file(\"private.pem\"),\n{Pub, Priv} = ecies_pem:decode_keypair(Pem),\nPub = ecies_pem:decode_public(Pem),\nPriv = ecies_pem:decode_private(Pem),\nfile:write_file(\"public.pem\", ecies_pem:encode_public(Pub)).\n```\n```shell\nopenssl ec -pubin -in public.pem -noout -text\n```\n### Customisation\n\nUsing `ecies:generate_key/1`, `ecies:public_encrypt/3`, `ecies:private_decrypt/3` functions which accepts extra `Params` argument you can customize elliptic curve and algorithms used in all steps of encryption/decryption process.\n\nThere are a few library API functions that helps with customisation:\n- `ecies:default_params/0` - returns default set of params\n- `ecies:supports/1`- which can be used to inspect lists of all supported curves, ciphers, hashs (digest types)\n\nWe also provide default params compatible with existing ECIES variants used in some other libraries.\n\n- `ecies_bitcore:default_params/0` - compatible with [bitcore](https://github.com/bitpay/bitcore-ecies/) ECIES implementation\n- `ecies_geth:default_params/0`, `ecies_geth:params_from_curve/1` - compatible with [ethereum's geth](https://github.com/ethereum/go-ethereum) ECIES implementation\n- `ecies_electrum:default_params/0` - compatible with [Electrum](https://github.com/spesmilo/electrum), [Electron Cash](https://github.com/Electron-Cash/Electron-Cash) and [ElectrumSV](https://github.com/electrumsv/electrumsv) ECIES implementation (see also [here](https://github.com/gitzhou/bitcoin-ecies))\n\nExample 1:\n```erlang\n% Alice and Bob agrees on the following params\nParams = #{\n  curve  =\u003e x25519,         % Edwards curve 25519\n  kdf    =\u003e {hkdf, sha256}, % HMAC-based Extract-and-Expand KDF with SHA256 hash\n  cipher =\u003e aes_256_ctr,\n  mac    =\u003e {hmac, sha256, 96} % HMAC with SHA256 and 96 bits output\n},\n  % Bob generates keys\n{BobPublicKey, BobPrivateKey} = ecies:generate_key(Params),\n% Alice knowing Bob's public key encrypts a message for him\nData = ecies:public_encrypt(BobPublicKey, \u003c\u003c\"top secret message\"\u003e\u003e, Params),\n% Bob is able to decrypt the message using his private key\n\u003c\u003c\"top secret message\"\u003e\u003e = ecies:private_decrypt(BobPrivateKey, Data, Params).\n```\nExample 2:\n```erlang\n% Decrypting electrum compatible message\nParams = ecies_electrum:default_params(),\nPrivateKey = binary:decode_hex(\u003c\u003c\"ee3231b5deea48b619814d72a6e1aa04a9f521df281afad5ada89f5393941b1c\"\u003e\u003e),\nMessageBase64 = \u003c\u003c\"QklFMQJdmY+9Ys1WjqANreLwXaau62N01r9lebJ9Rp7Az+XRMdNAVgg3J8EEVhni5gn2v+WOD59uDMDp0zY/xPT3IElReQo6XUCSMmgRgRtYl+TUEw==\"\u003e\u003e,\n\u003c\u003c\"hello world\"\u003e\u003e = ecies:private_decrypt(PrivateKey, MessageBase64, Params).\n```\n\n---\n\nThe list of all supported elliptic curves (`curve` param), ciphers (`cipher` param) and hash functions used by KDF and MAC \nalgorithms can be obtained using `ecies:supports/1` function:\n\n```erlang\n-spec supports(hashs)  -\u003e [digest_type()];\n              (curves) -\u003e [named_curve()];\n              (ciphers) -\u003e [cipher()];\n              (cmac_ciphers) -\u003e [cmac_cipher()];\n              (aead_ciphers) -\u003e [aead_cipher()].\n```\n\n\u003e [!NOTE]\n\u003e For Edwards Curves 25519 and 448 use `x25519`, `x448`, and not `ed25519`, `ed448`\n\nFor key derivation (`kdf` param) you can use:\n```erlang\n-type kdf_type() :: {hkdf, digest_type()} | % HMAC-based Extract-and-Expand Key Derivation Function (HKDF)\n                    {kdf, digest_type()}  | % ANSI-X9.63 KDF\n                    {concat_kdf, digest_type()}  | % NIST SP 800-56 Concatenation Key Derivation Function (see section 5.8.1).\n                    kdf_fun().\n% Custom KDF function\n-type kdf_fun()  :: fun((SharedKey :: binary(), Info :: binary(), Length :: pos_integer()) -\u003e Result :: binary()).\n```\n\nFor message authentication (`mac` param):\n```erlang\n-type mac_type()    :: {hmac, digest_type(), mac_bits()} | % HMAC for given digest function with specified output bits\n                       {cmac, cmac_cipher(), mac_bits()} | % CMAC with AES-*-CBC cipher and given output bits\n                       {aead, mac_bits()}. % Special case when AES CCM/GCM ciphers are used to just specify tag output bits \n-type mac_bits()    :: pos_integer() | default. % default atom means output size equal to given mac key length\n```\n\nLicense\n-------\n`ecies` library is MIT-licensed, as per [LICENSE.md](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplito%2Fecies-erl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplito%2Fecies-erl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplito%2Fecies-erl/lists"}