Mehdi Payervand
Mehdi Payervand

Reputation: 251

get double hash result like js-sha1 library in c#

I try to hash a double (1529480427715.5532) with SHA1 algorithm and i have this hash in c#:

but in fact i want to get this hash "da39a3ee5e6b4b0d3255bfef95601890afd80709" as result like when i'm using js-sha1 library.

Upvotes: 0

Views: 189

Answers (1)

xanatos
xanatos

Reputation: 111860

Given this code to convert from float64 (that is double in C#) to Uint8array, you can:

// c880857c399c7b9cc9c6395197e700543c400b17
var hash = sha1(convertTypedArray(new Float64Array([1529480427715.5532]), Uint8Array));

or even shorter, without using that link, because sha1 accepts ArrayBuffer as a parameter:

var hash = sha1(new Float64Array([1529480427715.5532]).buffer);

Note that sha1 accepts only some types of input, number isn't one of them.

From the examples of the library it seems strings, Array, Uint8Array, ArrayBuffer are supported.

As written by @Freggar,

// da39a3ee5e6b4b0d3255bfef95601890afd80709
var hash = sha1('');

And, using strings:

// 3e8f41233f90a85f9963afaa571ba76afb8bb08d
var hash = sha1('1529480427715.5532');

Upvotes: 2

Related Questions