CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/ssh-keys/fingerprint.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// Adapted from https://github.com/bahamas10/node-ssh-fingerprint
7
8
import md5 from "md5";
9
10
// add colons, 'hello' => 'he:ll:o'
11
const colons = (s: string) => s.replace(/(.{2})(?=.)/g, "$1:");
12
13
export function compute_fingerprint(pub: string | undefined): string {
14
if (pub == null) {
15
throw new Error("No valid SSH key value");
16
}
17
const pubbuffer = Buffer.from(pub, "base64");
18
const key = md5(pubbuffer);
19
return colons(key);
20
}
21
22