0
$\begingroup$

I want to use the asymmetric encription offered by a tool to encrypt my files and I would like to know if the following encryption process works, regardless of perhaps not optimal use.

  • Generate a 32-bytes-random-key inside the browser with window.crypto.getRandomValues

  • use sjcl crypto library for:

    • choosing AES algorythm cipher.aes
    • generating 4 words random IV vector random.randomWords(4, 0)
    • encrypting a file in GCM mode mode.gcm.encrypt (tag 128 bits)
    • concating IV and encrypted output producing the binaryFile1
  • use NaCl Networking and Cryptography library, through a tool that implements ECIES, for:

    • generating an encryptionKeypair using nacl.box.keyPair.fromSecretKey
    • encrypting the above 32-bytes-random-key with the ephemeralPublicKey (using the x25519 part of the schema x25519-xsalsa20-poly1305) producing the binaryFile2, a bundle containing the encrypted AES key and, among other metadata, the ephemeralPublicKey.
  • concat binaryFile2 + a-separator + binaryFile1 producing finalBinaryFile

  • keep the finalBinaryFile on the cloud until it is necessary to download it and then decrypt it through the reverse process using the secretKey I own.

To encrypt the files I could directly use the symmetric key keeping it safe but I would like to use a DB of shared static public keys, whose trustness I can assume valid.

$\endgroup$
5
  • $\begingroup$ What is the question? $\endgroup$
    – kelalaka
    May 11, 2022 at 10:41
  • $\begingroup$ I made the question explicit in the title. Thank you. $\endgroup$
    – blockmined
    May 11, 2022 at 10:44
  • 2
    $\begingroup$ Why don't you use well-maintained programs like Veracrypt or libraries like the age (age is a simple, modern and secure file encryption tool, format, and Go library.) $\endgroup$
    – kelalaka
    May 11, 2022 at 10:46
  • 1
    $\begingroup$ Complete reviews of cyptographic protocols and schemes is off topic. Using ECIES to encrypt a secret key is a bit spurious; you could use the key agreement part itself to establish a key. Of course, you'd also need to send the ephemeral public key for ECIES, something that is missing in your protocol. I don't see how you've established the static key pair of the receiver or how that public key is trusted, so the description is certainly not without fault nor complete. $\endgroup$
    – Maarten Bodewes
    May 11, 2022 at 12:27
  • $\begingroup$ Thank you for your remarks Maarten. Actually I forgot to mention that in the binaryFile2 there is also the ephemeral publick key so I will update the question. I am aware that I am asking about the validity regardless to the process of registration of the static key pair and relative trustness. $\endgroup$
    – blockmined
    May 11, 2022 at 12:47

1 Answer 1

2
$\begingroup$

NaCL provides a set of crypto_box methods which do this all in one go. Libsodium provides an even easier set of crypto_box_easy methods.

$\endgroup$
2
  • $\begingroup$ Thank you for your suggestion, My implementation has to be in javascript so I am just using a wrap of NaCl set that offers and manages key pair generations. $\endgroup$
    – blockmined
    May 11, 2022 at 14:39
  • 1
    $\begingroup$ There are JS bindings for libsodium as well. $\endgroup$ May 11, 2022 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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