webcrypto-core

esm
Common layer to be used by crypto libraries based on WebCrypto API for input validation.
Version 1.8.1 License MIT
Keywords
webcryptocryptopolyfillaesrsashaecshake
INSTALL
Type:
Version:
- Static
- Latest Patch
- Latest Minor
- Latest Major
- 1.8.1
- 1.8.0
- 1.7.9
- 1.7.8
- 1.7.7
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 0.1.27
- 0.1.26
- 0.1.25
- 0.1.24
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.0
- 1.0.19-next.0
<script type="module"> import webcryptoCore from 'https://cdn.jsdelivr.net/npm/webcrypto-core@1.8.1/+esm' </script>
webcrypto-core
We have created a number of WebCrypto polyfills including: node-webcrypto-ossl, node-webcrypto-p11, and webcrypto-liner. webcrypto-core
was designed to be a common layer to be used by all of these libraries for input validation.
Unless you intend to create a WebCrypto polyfill this library is probably not useful to you.
Installing
npm install webcrypto-core
Example
Current examples shows how you can implement your own WebCrypt interface
const core = require(".");
const crypto = require("crypto");
class Sha1Provider extends core.ProviderCrypto {
constructor() {
super();
this.name = "SHA-1";
this.usages = [];
}
async onDigest(algorithm, data) {
const hash = crypto.createHash("SHA1").update(Buffer.from(data)).digest();
return new Uint8Array(hash).buffer;
}
}
class SubtleCrypto extends core.SubtleCrypto {
constructor() {
super();
// Add SHA1 provider to SubtleCrypto
this.providers.set(new Sha1Provider());
}
}
class Crypto extends core.Crypto {
constructor() {
this.subtle = new SubtleCrypto();
}
getRandomValues(array) {
const buffer = Buffer.from(array.buffer);
crypto.randomFillSync(buffer);
return array;
}
}
const webcrypto = new Crypto();
webcrypto.subtle.digest("SHA-1", Buffer.from("TEST MESSAGE"))
.then((hash) => {
console.log(Buffer.from(hash).toString("hex")); // dbca505deb07e1612d944a69c0c851f79f3a4a60
})
.catch((err) => {
console.error(err);
});