mirror of
https://github.com/zadam/trilium.git
synced 2026-06-15 04:30:11 +02:00
30 lines
945 B
TypeScript
30 lines
945 B
TypeScript
import { CryptoProvider } from "@triliumnext/core";
|
|
import crypto from "crypto";
|
|
import { generator } from "rand-token";
|
|
|
|
const randtoken = generator({ source: "crypto" });
|
|
|
|
export default class NodejsCryptoProvider implements CryptoProvider {
|
|
|
|
createHash(algorithm: "sha1", content: string | Uint8Array): Uint8Array {
|
|
return crypto.createHash(algorithm).update(content).digest();
|
|
}
|
|
|
|
createCipheriv(algorithm: "aes-128-cbc", key: Uint8Array, iv: Uint8Array): { update(data: Uint8Array): Uint8Array; final(): Uint8Array; } {
|
|
return crypto.createCipheriv(algorithm, key, iv);
|
|
}
|
|
|
|
createDecipheriv(algorithm: "aes-128-cbc", key: Uint8Array, iv: Uint8Array) {
|
|
return crypto.createDecipheriv(algorithm, key, iv);
|
|
}
|
|
|
|
randomBytes(size: number): Uint8Array {
|
|
return crypto.randomBytes(size);
|
|
}
|
|
|
|
randomString(length: number): string {
|
|
return randtoken.generate(length);
|
|
}
|
|
|
|
}
|