Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with decrypt data ECIES #56

Open
janch11 opened this issue Apr 6, 2020 · 1 comment
Open

Problem with decrypt data ECIES #56

janch11 opened this issue Apr 6, 2020 · 1 comment
Labels

Comments

@janch11
Copy link

janch11 commented Apr 6, 2020

Hi,
I have problem with ECIES decrypter. I have very specific case, in which I want to decrypt some data from foreign source(c++ library). We have: encrypted data in Buffer, PrivateKey and IV, but we don't have MAC. Is there any posibility to decrypt data without encrypting erlier with eccrypto?
Best regards!

@tetratorus
Copy link

yes.

we've implemented the backend encryption in Golang (https://github.com/torusresearch/torus-public/blob/5b11e40819bb936d2d7fe7ea09d030917e3fce53/dkgnode/jrpc_handlers.go#L316) and have been decrypting it in the front-end using eccrypto.

The spec eccrypto uses for encryption and decryption is ECIES. A quick explanation for how this ECIES implementation in eccrypto works is it uses ECDH (elliptic curve diffie hellman) to generate a shared key: sha512(g^(x1.x2)). It then uses this shared key to encrypt using a symmetric key encryption scheme called AES.

only the first 32 bytes are used in the sha512 as the encryption key, since aescbc256 accepts a 256 bit key. the last 32 bytes are used for a MAC check,

var dataToMac = Buffer.concat([iv, ephemPublicKey, ciphertext]);

you can generate the MAC based off the line I've linked, and as long as you have libraries that support AESCBC256 encryption and some generic elliptic curve library you should be able to reproduce a compatible encrypted message that can be decrypted by eccrypto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants