@guanghechen/cipher-helper
Utility functions for cipher contents or files.
Install
-
npm
npm install --save @guanghechen/cipher-helper
-
yarn
yarn add @guanghechen/cipher-helper
Usage
-
AESCipherHelper
import { AESCipherHelper } from '@guanghechen/cipher-helper' const cipher = new AESCipherHelper() // Some options cipher.initFromSecret(cipher.createSecret()) // Or use password // encrypt / decrypt cipher.encrypt(Buffer.from('plain data')) // => Buffer cipher.decrypt(Buffer.from('cypher data')) // => Buffer // encrypt / decrypt file cipher.encryptFile('plain.txt', 'cipher.txt') cipher.decryptFile('cipher.txt', 'plain.txt') // encrypt / decrypt files cipher.encryptFile(['plain1.txt', 'plain2.txt'], 'cipher.txt') cipher.decryptFile(['cipher1.txt', 'cipher2.txt'], 'plain.txt')
-
CipherCatalog
import { AESCipherHelper, CipherCatalog } from '@guanghechen/cipher-helper' import path from 'path' const password = Buffer.from('password, such as `@guanghechen/cipher-helper`') const cipher = new AESCipherHelper() cipher.initFromPassword(password) const catalog = new CipherCatalog({ cipher, sourceRootDir: path.join(__dirname, 'workspace/source'), targetRootDir: path.join(__dirname, 'workspace/target'), }) catalog.calcAbsoluteSourceFilepath('a.md') // Resolve the absolute path of a source file. catalog.calcAbsoluteTargetFilepath('a.md') // Resolve the absolute path of a target file. catalog.calcRelativeSourceFilepath('<WORKSPACE>/a.md') // Resolve the relative path of the source file. catalog.calcRelativeTargetFilepath('<WORKSPACE>/a.md') // Resolve the relative path of the target file. catalog.checkIntegrity() // Check if the index file is damaged. catalog.cleanup() // Perform cleanup operations. catalog.decryptAll(bakSourceRootDir) // Decrypt all target files and output into the given directory. catalog.dump() // Dump catalog states. catalog.isModified('a.md') // Test whether the given file has changed. (provide a simple filtering for continued operations) catalog.load(cipheredCatalogIndex) // Load states from ciphered data string catalog.loadFroMFile('catalog.txt') // Load states from index files. catalog.reset() // Reset inner states. catalog.save('catalog.index.txt') // Dump catalog data and save into the index file. catalog.register(sourceFilepath) // Register a item into the catalog and perform some cleanup operations. catalog.touch() // Synchronize the lastCheckTime.
Overview
Name | Description |
---|---|
calcFingerprint |
Calc fingerprint of Buffer contents |
calcMac |
Calc mac (Message Authentication Code) |
calcMacFromFile |
Calc mac (Message Authentication Code) from file |
createRandomIv |
Create random initial vector |
createRandomKey |
Create random key of aes |
destroyBuffer |
Fill buffer with a random number |
destroyBuffers |
Fill buffers with random numbers |
streams2buffer |
Merge multiple read streams into Buffer serially |
AESCipherHelper |
A CipherHelper implementation with AES algorithm. |
CipherCatalog |
Catalog for managing source / target files and relationship maps |