简体   繁体   中英

How do I cipher plaintext using ECDH?

I'm looking for sample Java code to implement the cipher for ECDH encryption. I've already found the method to get the keys required but still haven't found a solution to encrypt the text. Appreciate if anyone can give some guidance.

Btw I am using SpongyCastle as I am programming for Android.

Many Thanks!

ECDH is not an encryption algorithm; it cannot encrypt some data you choose. It is a key agreement protocol, which results in a "shared secret": the data which both sender and receiver end up sharing is "secret" (only them know it) but they cannot control its contents.

The idea is that you can use the shared secret as the basis for a symmetric encryption algorithm. Since the shared secret has a relatively non-flexible format (with ECDH, the shared secret is an elliptic curve point, and about half of it is really secret), the normal way is to hash it with a secure hash function (say, SHA-256) and use the hash output (or part of it) as the actual encryption key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM