From cfd68605c69a4f89e0add9c8efa23bb93bb04cec Mon Sep 17 00:00:00 2001 From: Vivek Singh <47470314+heyitsvi@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:30:29 +0530 Subject: [PATCH] Add API documentation (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kasper Isager Dalsgarð --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index 6792ef1..cf571ee 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,54 @@ Cryptographic primitives for JavaScript. npm i bare-crypto ``` +## Usage + +```js +const crypto = require('bare-crypto') + +const hash = crypto.createHash('sha256') + +hash.update('Hello, world!') + +const digest = hash.digest('hex') + +console.log(digest) +``` + +## API + +#### `const hash = createHash(algorithm[, options])` + +Create a new `Hash` instance with the specified algorithm and options. The options are passed to [`new Transform()`](https://github.com/mafintosh/streamxts--new-streamtransformoptions). + +#### `const bytes = randomBytes(size)` + +Generate cryptographically secure random bytes. + +#### `randomBytes(size, callback)` + +Generate cryptographically secure random bytes, asynchronously providing the result in `callback`. The callback signature is `callback(err, buffer)`. + +#### `randomFill(buffer[, offset][, size])` + +Fill a buffer with cryptographically secure random bytes. + +#### `randomFill(buffer[, offset][, size], callback)` + +Fill a buffer with cryptographically secure random bytes, asynchronously providing the result in `callback`. The callback signature is `callback(err, buffer)` + +#### `constants.hash` + +The supported hash algorithms. + +Constant | Description +--- | --- +`MD5` | A widely-used 128-bit hash function, now considered insecure due to vulnerabilities to collision attacks. Still fast but not recommended for security-sensitive purposes. +`SHA1` | A 160-bit hash function, stronger than MD5 but also broken by collision attacks. Deprecated for most cryptographic uses due to security vulnerabilities. +`SHA256` | Part of the SHA-2 family, this 256-bit hash function is widely used and considered secure for most applications. Slower than MD5 and SHA1 but much more secure. +`SHA512` | Another member of the SHA-2 family, this 512-bit hash function offers greater security than SHA256 but is slower and produces larger hashes. Suitable for high-security environments. +`BLAKE2B256` | A fast, secure alternative to SHA-2 designed for efficiency, producing a 256-bit hash. It is optimized for performance while maintaining strong cryptographic security. + ## License Apache-2.0