Skip to content

Commit bc9302b

Browse files
committed
Checksum
1 parent 6a8d67b commit bc9302b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,9 +3312,38 @@ var memcached = new Memcached('localhost:11211', {retries:10,retry:10000,remove:
33123312
<b><a href="#">↥ back to top</a></b>
33133313
</div>
33143314

3315-
#### 76Q. ***How to use locale (i18n) in Node.js?***
3315+
## 76Q. ***How to generate and verify checksum of the given string in Node.js***
3316+
3317+
The **checksum** (aka **hash sum**) calculation is a one-way process of mapping an extensive data set of variable length (e.g., message, file), to a smaller data set of a fixed length (hash). The length depends on a hashing algorithm.
3318+
3319+
For the checksum generation, we can use node `crypto()` module. The module uses `createHash(algorithm)` to create a checksum (hash) generator. The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform.
3320+
3321+
**Example:**
3322+
3323+
```js
3324+
const crypto = require('crypto');
3325+
3326+
// To get a list of all available hash algorithms
3327+
crypto.getHashes() // [ 'md5', 'sha1', 'sha3-256', ... ]
3328+
3329+
3330+
// Create hash of SHA1 type
3331+
const key = "MY_SECRET_KEY";
3332+
3333+
3334+
// 'digest' is the output of hash function containing
3335+
// only hexadecimal digits
3336+
hashPwd = crypto.createHash('sha1').update(key).digest('hex');
3337+
3338+
console.log(hashPwd); //ef5225a03e4f9cc953ab3c4dd41f5c4db7dc2e5b
3339+
```
3340+
3341+
<div align="right">
3342+
<b><a href="#">↥ back to top</a></b>
3343+
</div>
3344+
33163345
#### 77Q. ***Explain error handling in Node.js?***
3317-
#### 78Q. ***How to generate and verify checksum of the given string in Node.js***
3346+
#### 78Q. ***How to use locale (i18n) in Node.js?***
33183347

33193348
<div align="right">
33203349
<b><a href="#">↥ back to top</a></b>

0 commit comments

Comments
 (0)