Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js and sha1

http://www.php.net/manual/en/function.sha1.php

string sha1 ( string $str [, bool $raw_output = false ] )

If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number.


crypto = require("crypto");
console.log( new Buffer(crypto.createHash('sha1').update("some text").digest()).toString('base64') );
// N8KqY8OHc8KYw5lURzJiw6HCoAV8HmMuw5p3
console.log( new Buffer(crypto.createHash('sha1').update("some text").digest("hex")).toString('base64') );
// MzdhYTYzYzc3Mzk4ZDk1NDQ3MzI2MmUxYTAwNTdjMWU2MzJlZGE3Nw==
console.log( new Buffer(crypto.createHash('sha1').update("some text").digest("base64")).toString('base64') );
// TjZwangzT1kyVlJITW1MaG9BVjhIbU11Mm5jPQ==

<?php
echo base64_encode(sha1("some text"));
// MzdhYTYzYzc3Mzk4ZDk1NDQ3MzI2MmUxYTAwNTdjMWU2MzJlZGE3Nw==
echo base64_encode(sha1("some text", true)); // <-- how to reproduce it on the nodejs?
// N6pjx3OY2VRHMmLhoAV8HmMu2nc=
?>
like image 958
sergey Avatar asked Mar 16 '13 02:03

sergey


People also ask

Why is SHA-1 no longer secure?

SHA-1 is a legacy cryptographic hashing algorithm that is no longer deemed secure. Using the SHA-1 hashing algorithm in digital certificates could allow an attacker to spoof content, perform phishing attacks, or perform man-in-the-middle attacks.

Is cryptography supported in node JS?

The Node. js Crypto module supports cryptography. It provides cryptographic functionality that includes a set of wrappers for open SSL's hash HMAC, cipher, decipher, sign and verify functions.

Why do we use SHA-1?

SHA-1 (short for Secure Hash Algorithm 1) is one of several cryptographic hash functions. It's most often used to verify a file has been unaltered. This is done by producing a checksum before the file has been transmitted, and then again once it reaches its destination.

Is SHA-1 algorithm safe?

SHA-1 (Secure Hash Algorithm 1) dates back to 1995 and has been known to be vulnerable to theoretical attacks since 2005.


1 Answers

> crypto.createHash('sha1').update("some text").digest('base64')
'N6pjx3OY2VRHMmLhoAV8HmMu2nc='
like image 109
Blender Avatar answered Sep 26 '22 00:09

Blender