pub struct ECIES;Expand description
ECIES encryption with Electrum and Bitcore variants.
Electrum uses BIE1 magic bytes, derives IV from ECDH shared secret, and uses AES-128-CBC.
Bitcore uses a random IV prepended to ciphertext, derives a 32-byte key from ECDH shared secret, and uses AES-256-CBC.
Implementations§
Source§impl ECIES
impl ECIES
Sourcepub fn electrum_encrypt(
plaintext: &[u8],
recipient_pub_key: &PublicKey,
sender_priv_key: Option<&PrivateKey>,
) -> Result<Vec<u8>, CompatError>
pub fn electrum_encrypt( plaintext: &[u8], recipient_pub_key: &PublicKey, sender_priv_key: Option<&PrivateKey>, ) -> Result<Vec<u8>, CompatError>
Encrypt plaintext using the Electrum ECIES variant (BIE1 format).
Format: “BIE1” (4 bytes) || ephemeral_pubkey (33 bytes) || ciphertext || HMAC (32 bytes)
If sender_priv_key is provided, it is used instead of an ephemeral key.
Sourcepub fn electrum_decrypt(
ciphertext: &[u8],
recipient_priv_key: &PrivateKey,
) -> Result<Vec<u8>, CompatError>
pub fn electrum_decrypt( ciphertext: &[u8], recipient_priv_key: &PrivateKey, ) -> Result<Vec<u8>, CompatError>
Decrypt ciphertext using the Electrum ECIES variant (BIE1 format).
Expects format: “BIE1” (4) || pubkey (33) || ciphertext || HMAC (32) Minimum length: 4 + 33 + 16 + 32 = 85 (at least one AES block)
Sourcepub fn bitcore_encrypt(
plaintext: &[u8],
recipient_pub_key: &PublicKey,
sender_priv_key: Option<&PrivateKey>,
) -> Result<Vec<u8>, CompatError>
pub fn bitcore_encrypt( plaintext: &[u8], recipient_pub_key: &PublicKey, sender_priv_key: Option<&PrivateKey>, ) -> Result<Vec<u8>, CompatError>
Encrypt plaintext using the Bitcore ECIES variant.
Format: ephemeral_pubkey (33) || iv (16) || aes_ciphertext || HMAC (32) HMAC is over iv + aes_ciphertext only (not including pubkey).
Uses AES-256-CBC with a 32-byte key derived from ECDH.
Sourcepub fn bitcore_decrypt(
ciphertext: &[u8],
recipient_priv_key: &PrivateKey,
) -> Result<Vec<u8>, CompatError>
pub fn bitcore_decrypt( ciphertext: &[u8], recipient_priv_key: &PrivateKey, ) -> Result<Vec<u8>, CompatError>
Decrypt ciphertext using the Bitcore ECIES variant.
Expects format: pubkey (33) || iv (16) || aes_ciphertext || HMAC (32) HMAC is verified over iv + aes_ciphertext only.