Code Monkey home page Code Monkey logo

key-fingerprint's Introduction

key-fingerprint Build Status Coverage Status

Node.js library to easy calculate MD*, SHA*, etc fingerprint of a public/private key.

Installation

npm install key-fingerprint

OR

yarn add key-fingerprint

Usage

fingerprint(key: string, algorithm: string = 'sha512', colons: boolean = false)

OR

export enum SUPPORTED_ALGORITHM {
  MD4 = 'md4',
  MD5 = 'md5',
  RMD160 = 'rmd160',
  SHA1 = 'sha1',
  SHA224 = 'sha224',
  SHA256 = 'sha256',
  SHA384 = 'sha384',
  SHA512 = 'sha512',
}

export enum SUPPORTED_ENCODING {
  HEX = 'hex',
  LATIN1 = 'latin1',
  BASE64 = 'base64',
}

interface IConfig {
  algorithm: SUPPORTED_ALGORITHM,
  colons: boolean,
  encoding: SUPPORTED_ENCODING,
}

const DEFAULT_CONFIGURATION: IConfig = {
  algorithm: SUPPORTED_ALGORITHM.SHA256,
  colons: false,
  encoding: SUPPORTED_ENCODING.HEX,
}

fingerprint(key: string, configuration: Partial<IConfig>)

Supported algorithms

  • MD4
  • MD5
  • RMD160
  • SHA1
  • SHA224
  • SHA256
  • SHA384
  • SHA512

Examples

import { fingerprint } from 'key-fingerprint'

const key = '-----BEGIN PUBLIC KEY-----\n.........'
const sha256 = fingerprint(key, 'sha256') // => 'ab12ef12....
const sha256WithColons = fingerprint(key, 'sha256', true) // => 'ab:12:ef:12....
import { fingerprint } from 'key-fingerprint'

const key = '-----BEGIN PUBLIC KEY-----\n.........'
const config = { encoding: 'base64', algorithm: 'sha512' } // options fallback to default if missing
const sha512 = fingerprint(key, config) // => 'ZGlvIHBvcmN...

key-fingerprint's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

key-fingerprint's Issues

Code throws typescript error

Error:

node_modules/key-fingerprint/index.ts(52,74): error TS2345: Argument of type 'SUPPORTED_ENCODING' is not assignable to parameter of type 'BinaryToTextEncoding'

Version: key-fingerprint
Node version 12 and above

add cli interface

it would be nice to wrap the library with a cli in order to easily calculate fingerprints via npx.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.