pepto
v1.0.7
Published
Generate a hex string digest from a given message.
Downloads
464
Readme
pepto
Generate a hex string digest from a given message. See SubtleCrypto.digest()
and Replit demo.
Quick Start
import { digest } from 'pepto';
await digest('SHA-256', 'Hello, World!');
Installation
NPM:
npm install pepto
Yarn:
yarn add pepto
Usage
Import ES Modules:
import { digest } from 'pepto';
Require with CommonJS:
const { digest } = require('pepto');
Hash message with SHA-1
algorithm:
await digest('SHA-1', 'message');
Hash message with SHA-256
algorithm:
await digest('SHA-256', 'message');
Hash message with SHA-384
algorithm:
await digest('SHA-384', 'message');
Hash message with SHA-512
algorithm:
await digest('SHA-512', 'message');
Use promise instead of async-await:
digest('SHA-512', 'message').then((hex) => console.log(hex));
FAQ
ReferenceError: TextEncoder is not defined
If you get this error in your Jest tests, then add the following to your setupTests.ts
:
import { TextEncoder } from 'util';
window.TextEncoder = TextEncoder;
Or add the following to your setupTests.js
:
const { TextEncoder } = require('util');
window.TextEncoder = TextEncoder;