Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including secure-compare-native with all npm packages installed. Try it out:

var secureCompareNative = require("secure-compare-native")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

secure-compare-native v1.0.3

Constant-time safe comparison using Node.js native crypto.timingSafeEqual

secure-compare-native

Constant-time safe comparison using Node.js native crypto.timingSafeEqual.

Installation

npm install secure-compare-native

Usage

Strings:

const { secureCompare } = require("secure-compare-native");

secureCompare("abc", "abc"); // true
secureCompare("hello", "abc"); // false

Buffers:

const { secureCompareBuffer } = require("secure-compare-native");

const buff1 = Buffer.from("abc");
const buff2 = Buffer.from("hello");

secureCompareBuffer(buff1, buff1); // true
secureCompareBuffer(buff2, buff1); // false

Performance

  • secureCompare is about twice slower than secure-compare on Node v12.
  • secureCompareBuffer is fast when you compare buffers.

License

MIT.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free