https://github.com/phra/key-fingerprint
Node.js library to easy calculate MD*, SHA*, etc fingerprint of a public/private key in HEX encoding.
https://github.com/phra/key-fingerprint
Last synced: over 1 year ago
JSON representation
Node.js library to easy calculate MD*, SHA*, etc fingerprint of a public/private key in HEX encoding.
- Host: GitHub
- URL: https://github.com/phra/key-fingerprint
- Owner: phra
- License: mit
- Created: 2017-10-09T14:49:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-24T21:28:13.000Z (almost 9 years ago)
- Last Synced: 2024-05-02T00:10:24.959Z (about 2 years ago)
- Language: TypeScript
- Homepage:
- Size: 71.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# key-fingerprint [](https://travis-ci.org/phra/key-fingerprint) [](https://coveralls.io/github/phra/key-fingerprint?branch=master)
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
```typescript
fingerprint(key: string, algorithm: string = 'sha512', colons: boolean = false)
```
OR
```typescript
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)
```
## Supported algorithms
- MD4
- MD5
- RMD160
- SHA1
- SHA224
- SHA256
- SHA384
- SHA512
## Examples
```typescript
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....
```
```typescript
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...
```