ecies / rs-wasm

A WASM binding for eciesrs
https://ecies-wasm.vercel.app/
MIT License
15 stars 5 forks source link

How to get ciphertext, ephemPublicKey from encrypted like in eccrypto example? #14

Closed VityaSchel closed 9 months ago

VityaSchel commented 9 months ago

I'm trying to adapt example from Payselection to use it in browsers, and luckily first part with public key and encryption worked. However, I have no clue how to get encrypted.ciphertext, encrypted.ephemPublicKey, encrypted.iv, encrypted.mac properties because ecies.encrypt methods returns Uint8Array

kigawas commented 9 months ago

Under the default configuration, the payload format is:

+-------------------------------+----------+----------+-----------------+
| 65 Bytes                      | 16 Bytes | 16 Bytes | == data size    |
+-------------------------------+----------+----------+-----------------+
| Sender Public Key (ephemeral) | Nonce/IV | Tag/MAC  | Encrypted data  |
+-------------------------------+----------+----------+-----------------+
|           Secp256k1           |              AES-256-GCM              |
+-------------------------------+---------------------------------------+

UInt8Array is literally byte array, you can just array.slice(start, end). Note that the key derivation is HKDF-SHA256 and symmetric cipher is AES-256-GCM (or XChaCha20-Poly1305 by config), which are different from eccrypto

VityaSchel commented 9 months ago

It turns out they have their own library for managing crypto. Very much thanks for your explanation though!

Алгоритм подключения токена.docx