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 withwindow.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
- choosing AES algorythm
use NaCl Networking and Cryptography library, through a tool that implements ECIES, for:
- generating an
encryptionKeypair
usingnacl.box.keyPair.fromSecretKey
- encrypting the above
32-bytes-random-key
with theephemeralPublicKey
(using thex25519
part of the schemax25519-xsalsa20-poly1305
) producing thebinaryFile2
, a bundle containing the encrypted AES key and, among other metadata, theephemeralPublicKey
.
- generating an
concat
binaryFile2
+a-separator
+binaryFile1
producingfinalBinaryFile
keep the
finalBinaryFile
on the cloud until it is necessary to download it and then decrypt it through the reverse process using thesecretKey
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.
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$