crypto_14.py 586 B

1234567891011121314151617
  1. def encrypt_key(key, nonce, data):
  2. """ use "key" and "nonce" to generate a one time key and en-/decrypt
  3. "data" with the one time key.
  4. Args
  5. key: encryption key
  6. nounce: exactly once used string (try a time-based UUID)
  7. data: the encrypted data
  8. Returns
  9. ciphertext: AES256 encrypted data
  10. """
  11. key = clean_string(key)
  12. key = SHA256d(key).digest()
  13. nonce_hash = SHA256d(nonce).digest()# assert 32 bytes key
  14. enc_key = aes(key, nonce_hash) # generate encryption key
  15. return aes(enc_key, data)