Create a signature of your data with Erlang

October 27, 2008

-module(signit.erl).
-export(start/0,sha_sign/0).

start() -> application:start(crypto).

%% Sign the data using SHA.
%% This will return a 20 byte key for the data
sha_sign(Data) ->
    Sha_data = crypto:sha(Data),
    Sha_list = binary_to_list(Sha_data),
    lists:flatten(list_to_hex(Sha_list)).

%% Crypto doesn't have a hexdigest method. I found the code below
%% here
%% Convert Integer from the SHA to Hex
list_to_hex(L)->
       lists:map(fun(X) -> int_to_hex(X) end, L).

int_to_hex(N) when N < 256 ->
       [hex(N div 16), hex(N rem 16)].

hex(N) when N < 10 ->
       $0+N;
hex(N) when N >= 10, N < 16 ->
       $a + (N-10).

writing theses cheap writing service introduction to a research paper