Calculate SHA1 and SHA 256 of Certificate using Node or NPM package or Javascript

import "./styles.css";
import { sha256 } from "js-sha256";
//import { sha1 } from "js-sha1";
export default function App() {
const crypto = require("crypto");

function getHash(content, inputEncoding = "utf8", outputEncoding = "base64") {
const shasum = crypto.createHash("sha256");
shasum.update(content, inputEncoding);
const res = shasum.digest(outputEncoding);
return res;
}
const sha1 = require("js-sha1");
const key = "sudhir";

const certificate = key
.toString()
.split("\n")
.filter((line) => !line.includes("-----"))
.map((line) => line.trim())
.join("");

// [NODE VERSION] openssl x509 -noout -fingerprint -sha256 -inform pem -in cert.crt
const fingerPrint = getHash(certificate, "base64", "hex").toUpperCase();
console.log("SHA256 With colons", fingerPrint.match(/.{1,2}/g).join(":"));

// display the result

return (
<div className="App">
<h1>Hello CodeSandbox</h1>
sha1 of text "sudhir" is {sha1("sudhir")}
<br />
<br />
<br />
sha256 of text "sudhir" is {sha256("sudhir")}
<br />
<br />
<br />
<br />
sha256 of text "sudhir" with colons, for this check console log <br />
<h2>Start editing to see some magic happen!</h2>
</div>
);
}









A simple SHA1 hash function for JavaScript supports UTF-8 encoding.

Demo

SHA1 Online

Download

Compress
Uncompress

Installation

You can also install js-sha1 by using Bower.

bower install js-sha1

For node.js, you can use this command to install:

npm install js-sha1

Usage

You could use like this:

sha1('Message to hash');
var hash = sha1.create();
hash.update('Message to hash');
hash.hex();

If you use node.js, you should require the module first:

sha1 = require('js-sha1');

It supports AMD:

require(['your/path/sha1.js'], function(sha1) {
// ...
});

Example

sha1(''); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1('The quick brown fox jumps over the lazy dog'); // 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
sha1('The quick brown fox jumps over the lazy dog.'); // 408d94384216f890ff7a0c3528e8bed1e0b01621
 
// It also supports UTF-8 encoding
sha1('中文'); // 7be2d2d20c106eee0836c9bc2b939890a78e8fb3
 
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
sha1([]); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1(new Uint8Array([])); // da39a3ee5e6b4b0d3255bfef95601890afd80709
 
// Different output
sha1(''); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1.hex(''); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1.array(''); // [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]
sha1.digest(''); // [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]
sha1.arrayBuffer(''); // ArrayBuffer

License

Comments

Popular posts from this blog

My Response is on my own Website : Best Quality Backlink Strategy

Why is Digital Marketing Important? What are the Advantages of Digital Marketing?

Hottest Snapchat girls usernames online