Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The rev-hash npm package is used to generate a hash from a file or string content. This is particularly useful for cache busting in web development, where you need to ensure that users get the latest version of a file.
Generate hash from file content
This feature allows you to generate a hash from the content of a file. You read the file into a buffer and then pass that buffer to the rev-hash function to get the hash.
const revHash = require('rev-hash');
const fs = require('fs');
const buffer = fs.readFileSync('path/to/file');
const hash = revHash(buffer);
console.log(hash);
Generate hash from string content
This feature allows you to generate a hash from a string. You simply pass the string to the rev-hash function to get the hash.
const revHash = require('rev-hash');
const content = 'Hello, world!';
const hash = revHash(content);
console.log(hash);
The hasha package is a versatile hashing library that supports multiple hashing algorithms like MD5, SHA-1, SHA-256, etc. It can hash strings, buffers, and even streams. Compared to rev-hash, hasha offers more flexibility in terms of hashing algorithms and input types.
The crypto package is a built-in Node.js module that provides cryptographic functionality, including a wide range of hash algorithms. It is more complex and powerful than rev-hash, offering more control over the hashing process but requiring more setup.
The md5-file package is specifically designed to generate MD5 hashes from files. It is similar to rev-hash in that it focuses on file content hashing, but it is limited to the MD5 algorithm.
Create a hash for file revving
It will create an md5
hash from an input buffer or string, and truncate it to 10 characters, which is unique enough for this purpose.
If you think you need a different hash algorithm or a longer hash, you're wrong.
npm install rev-hash
import fs from 'node:fs';
import revisionHash from 'rev-hash';
revisionHash(fs.readFileSync('unicorn.png'));
//=> 'bb9d8fe615'
revisionHash('Lorem ipsum dolor sit amet');
//=> 'fea80f2db0'
Type: Uint8Array | string
The data to create a hash from.
FAQs
Create a hash for file revving
We found that rev-hash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.