anchor.diff:              {ok, Req3, FieldList1, FileList};
             {file, FieldName, Filename, CType, CTransferEncoding} ->
   
  +            AESKey = crypto:strong_rand_bytes(32), %% 256 bts long
  +            AESIV = crypto:strong_rand_bytes(16),
               FileKey = lists:concat([
                 binary_to_list(UKey),
                 "_",
                 hash_md5:build(binary_to_list(Filename))
               ]),
  +            FileKeyBin = list_to_binary(FileKey),
  +
  +            CryptoState = crypto:stream_init(aes_ctr, AESKey, AESIV),
   
               Opts =
                 case couch:get("user_uploads", FileKey) of
  
positive.code:             ])},
  
              {ok, ResultDoc} = couch:save("user_uploads", Doc),
  
              FileList1 = lists:append([{Filename, ResultDoc}], FileList),
  
  
negative.code:       {ok, Req2, FieldList, FileList}
    end.
  
  stream_file(Req, UploadRef, CryptoState) ->
    case cowboy_req:part_body(Req) of
      {ok, Body, Req2} ->
        {NewCryptoState, CipherBody} = crypto:stream_encrypt(CryptoState, Body),
        ok = couch:stream_attach(UploadRef, CipherBody),
        {ok, Result} = couch:stream_attach_done(UploadRef),
        {ok, Result, Req2, NewCryptoState};
      {more, Body, Req2} ->
        {NewCryptoState, CipherBody} = crypto:stream_encrypt(CryptoState, Body),
        ok = couch:stream_attach(UploadRef, CipherBody),
        stream_file(Req2, UploadRef, NewCryptoState)
    end.