key-fingerprint
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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(keystring, algorithmstring = 'sha512', colonsboolean = 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(keystring, configurationPartial<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 sha256 = fingerprint(key, config) // => 'ab12ef12....
const sha256WithColons = fingerprint(key, 'sha256', true) // => 'ab:12:ef:12....

Readme

Keywords

none

Package Sidebar

Install

npm i key-fingerprint

Weekly Downloads

1,078

Version

1.1.0

License

MIT

Last publish

Collaborators

  • phra