Skip to content

Instantly share code, notes, and snippets.

@Arbow
Created October 28, 2008 02:08
Show Gist options
  • Save Arbow/20279 to your computer and use it in GitHub Desktop.
Save Arbow/20279 to your computer and use it in GitHub Desktop.
% Create a signature of your data with Erlang
-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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment