I'm writing a coursework and right now I've implemented the ECDSA algorithm, but I also need to encrypt and decrypt small text files (.txt) using elliptic curve cryptography.

The problem is that I do not know how to represent the message in the file.

  • 2
    $\begingroup$ Is implementing ECIES allowed? That's a way of doing public key encryption with Elliptic Curves that doesn't involve translating the plaintext into a point. $\endgroup$ – poncho May 19 '15 at 17:35

I don't know your exact scenario. However you have two options to encrypt data using elliptic curve cryptography (ECC). I'd recommend going with the first option I present.

  1. Use elliptic curve integrated encryption scheme (ECIES). ECIES basically performs ElGamal-like encryption on a key. The key is generated at random and encrypted like in ElGamal (replace the multiply operations with add operations). One then can use this symmetric key to symmetricly encrypt and authenticate the data. ECIES defines how to exactly do that. You then go ahead and simply process the data as you normally would using a symmetric encryption scheme.
  2. Use generalized ElGamal on elliptic curves (no abbreviation, likely never deployed or proposed outside of ECIES). You can as well simply use the generalized ElGamal construction and somehow represent the data you want to encrypt as a point on your curve (which is harder than it sounds).
    I do not recommend this method. The reason is that you're limited to a message space of 256 to 512 bit (32-64 bytes) and that representing your message may actually be quite difficult, as the reconstruction of the message data from the "decrypted" point won't be easy.

If you're question was only aiming at "How can I represent my bytes in the textfile for the encryption?", then by using approach no. 1 the solution is rather straightforward and with approach no. 2 you have to invent some scheme yourself to aid re-construction. This could go as follows:

  1. Represent your message as octet string $B$.
  2. Convert the octet string to an integer $b$.
  3. Initialize $c=0$
  4. Check if $b$ is a valid x-coordinate on your curve, if yes go to step 6
  5. Set $b=b+1$ and $c=c+1$ and go to step 4
  6. Encrypt the data and append $c$ (maybe with some sort of separator)

Reconstruction should be more easy. You retrieve $b$ by decrypting the message and setting $b$ to be the x-coordinate of the resulting point. Now you simply subract $c$ from $b$ yielding the original $b$ value and making you able to reconvert the integer to a byte array (the text in your file).

Note: If an attacker tampers with $c$, he can let you decrypt the ciphertext to arbitrary messages. Because of this property you should always prefer ECIES.

| improve this answer | |

Represent the text message as byte array. Note that, EC generally used for Diffie–Hellman Key Exchange and Digital Signature. The following link is about En-/decryption with elliptic curve integrated encryption system (ECIES) which may be helpful to you: Code Examples – En-/Decryption with ECIES

| improve this answer | |
  • $\begingroup$ Please explain why down vote? $\endgroup$ – rakeb.mazharul May 21 '15 at 11:24
  • 1
    $\begingroup$ I didn't downvote, but at a minimum your answer is "weird". First you state that the user should use byte arrays, without any explanation why. Then you say that ECC (EC = elliptic curve, ECC= elliptic curve crypto) is primarily used with ECDH and ECDSA and you just put the OP a link, without any explanation (you're linking to ECIES, which you didn't mention) and the link is even "bad" formatted (plain link text) $\endgroup$ – SEJPM May 21 '15 at 11:53
  • 2
    $\begingroup$ This does not appear to answer the question in any meaningful sense. $\endgroup$ – Ilmari Karonen May 21 '15 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.