anchor.diff:      {false,[]}.
   
   
  -
  -%% cookie_encrypt_data(Data,Key)-> binary()
  -%%                                Data = Key = iolist() | binary
  -cookie_encrypt_data(Data,Key) ->
  +encrypt_data(Data,Key) ->
       IV = crypto:rand_bytes(16),
       Crypt=crypto:aes_cfb_128_encrypt(Key, IV, Data),
       <<IV/binary,Crypt/binary>>.
  -cookie_decrypt_data(<<IV:16,Crypt/binary>>,Key) ->
  +decrypt_data(<<IV:16/binary,Crypt/binary>>,Key) ->
       crypto:aes_cfb_128_decrypt(Key, IV,Crypt).
   
  -cookie_gen_key(ExpirationTime,ServerKey)->
  +gen_key(ExpirationTime,ServerKey)->
       crypto:md5_mac(ServerKey, [ExpirationTime]).
  -cookie_gen_hmac(ExpirationTime,Data,SessionKey,Key)->
  +gen_hmac(ExpirationTime,Data,SessionKey,Key)->
       crypto:sha_mac(Key,[ExpirationTime,Data,SessionKey]).
   
   %% @doc Using 
  
positive.code:     {false,[]};
  check_session_cookie([],_,_,_) ->
      {false,[]};
  check_session_cookie(Cookie,ExpirationTime,FSessionKey,ServerKey) when is_binary(Cookie)->
      {P1,_}=binary:match(Cookie,<<",">>),
      ExpirationTime1=binary:part(Cookie,0,P1),
      Data=binary:part(Cookie,P1+1,byte_size(Cookie)-20),
      Hmac=binary:part(Cookie,byte_size(Cookie)-20,20),
      check_session_cookie(binary_to_list(ExpirationTime1),Data,Hmac,ExpirationTime,FSessionKey,ServerKey);
  check_session_cookie(_,_,_,_) ->
      {false,[]}.
  check_session_cookie(ExpirationTime1, EData, BHmac,ExpirationTime,FSessionKey,ServerKey) 
    when is_integer(ExpirationTime) , is_list(ServerKey), is_list(ExpirationTime1)->
      ExpTime=list_to_integer(ExpirationTime1),
      Key=cookie_gen_key(ExpirationTime1,ServerKey),
      Data=cookie_decrypt_data(binary_to_list(EData),Key),
      Hmac2=cookie_gen_hmac(ExpirationTime1,Data,FSessionKey(ExpirationTime1),Key),
      io:format("~p  ====  ~p",[Hmac2,BHmac]),
      if ExpTime<ExpirationTime -> {false,[ExpirationTime1,binary_to_list(Data)]};
         true -> 
  	    if Hmac2==BHmac -> {true,[ExpirationTime1,binary_to_list(Data)]};
  
negative.code: -module(mochiweb_session).
  -export([generate_session_data/4,generate_session_cookie/4,check_session_cookie/4]).
  -export([cookie_encode/1,cookie_decode/1,timestamp_sec/1]).%Useful fuctions for more specific purposes
  
  %% @spec generate_session_data(ExpirationTime,Data :: string(),FSessionKey : function(A),ServerKey) -> string()
  %% @doc generates a secure encrypted string convining all the parameters.
  %%      The expiration time is considered in seconds
  generate_session_data(ExpirationTime,Data,FSessionKey,ServerKey) when is_integer(ExpirationTime),is_list(Data), is_function(FSessionKey)->
      BData=list_to_binary(Data),
      ExpTime=integer_to_list(ExpirationTime),
      BExpTime=list_to_binary(ExpTime),
      Key=gen_key(ExpTime,ServerKey),
      Hmac=gen_hmac(ExpTime,BData,FSessionKey(integer_to_list(ExpirationTime)),Key),
      EData=encrypt_data(BData,Key),
      bin_to_hexstr(<< BExpTime/binary,",", EData/binary,Hmac/binary>>).
  
  %% @spec generate_session_data(UserName,ExpirationTime,SessionExtraData,FSessionKey : function(A),ServerKey) -> mochiweb_cookie()
  %% @doc generates a secure encrypted cookie using the generate_session_data function.
  