samedi 24 janvier 2015

Encrypting files securely using user supplied password



I'm currently trying to build a (sort of) secure, desktop based RTF text editor written for node-webkit using node.js. Based on some answers that I read here, such as How can I securely convert a "string" password to a key used in AES? and Recommended # of iterations when using PKBDF2-SHA256?, amongst others, I've come up with the following system. However, I'm rather unsure about the manner in which I've combined these algorithms, and I was hoping someone could check the system.


On first time application initialization:



  1. Generate 1024 cryptographically secure pseudorandom bytes (k)

  2. Generate 256 more ^ as a salt (s)

  3. Ask for user password (p)

  4. Stretch p using PBKDF-2 using s as salt, 64K rounds (n = number of rounds) to a length of 512 bytes (length = l) (P) (takes a little over a second on my system)

  5. Encrypt k using AES-CBC with P as key (K)

  6. Store s||n||l||K on disk


For encrypting and then saving a new file:



  1. Ask for user password (p)

  2. Read s||n||l||K from disk

  3. As in step 3 above, stretch p to P using s, n and l from step 2

  4. Decrypt K using P

  5. Use k to encrypt file data using AES CBC; save to disk


Possible concerns (keeping in mind that this is supposed to be usable on a modern laptop/desktop) include:



  • magic numbers (64K, 512, 1024)

  • no IV (not sure if it's necessary)

  • something about some combination of algorithms

  • some other stupid mistake





Aucun commentaire:

Enregistrer un commentaire