Skip to content

Instantly share code, notes, and snippets.

@kumavis
Created March 5, 2015 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumavis/2a34b865c8ef504f722b to your computer and use it in GitHub Desktop.
Save kumavis/2a34b865c8ef504f722b to your computer and use it in GitHub Desktop.
start (secret) -> return apiObject with [encrypt, decrypt] with plaintext secret stored in closure
encrypt (input) -> generate salt, iv, additionalData, -> generate hash from salt and secret -> generate key from hash -> encrypt with key -> return json string with salt, iv, additionalData, and encrypted data (edited)
decrypt(input) -> read salt, iv, additionalData -> generate hash from salt and secret -> generate key from hash -> decrypt with key -> return unecrypted data
and the 'encrypted text' includes plaintext metadata about the encryption settings (salt, iv, additionalData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment