Skip to content

shahradelahi/timing-safe-compare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

timing-safe-compare
CI NPM Version MIT License npm bundle size Install Size

@se-oss/timing-safe-compare provides constant-time string and buffer comparison for Node.js and browsers to prevent timing attacks.


πŸ“¦ Installation

npm install @se-oss/timing-safe-compare
Install using your favorite package manager

pnpm

pnpm install @se-oss/timing-safe-compare

yarn

yarn add @se-oss/timing-safe-compare

πŸ“– Usage

String Comparison

Compare two strings in constant time. This is useful for comparing passwords, tokens, or any other sensitive data where the length is already known or handled.

import { safeCompare } from '@se-oss/timing-safe-compare';

if (safeCompare(inputPassword, storedPassword)) {
  // Passwords match
}

Buffer Comparison

Compare two Uint8Array (or Buffer in Node.js) instances in constant time. Note that both buffers must have the same length.

import { timingSafeEqual } from '@se-oss/timing-safe-compare';

const a = new Uint8Array([1, 2, 3]);
const b = new Uint8Array([1, 2, 3]);

if (timingSafeEqual(a, b)) {
  // Buffers are equal
}

πŸ“š Documentation

For all configuration options, please see the API docs.

🀝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.

Thanks again for your support, it is much appreciated! πŸ™

License

MIT Β© Shahrad Elahi and contributors.

About

πŸ” Isomorphic constant-time string and buffer comparison to prevent timing attacks.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors