6.0.0-alpha.17 • Published 4 months ago

@guanghechen/helper-cipher-file v6.0.0-alpha.17

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Utility functions for encrypt / decrypt files.

Install

  • npm

    npm install --save @guanghechen/helper-cipher-file
  • yarn

    yarn add @guanghechen/helper-cipher-file

Usage

  • FileCipherPathResolver

    import path from 'node:path'
    import url from 'node:url'
    import { FileCipherPathResolver } from '@guanghechen/helper-cipher-file'
    
    const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
    const sourceRootDir = path.join(__dirname, 'src')
    const encryptedRootDir = path.join(__dirname, 'lib')
    const pathResolver = new FileCipherPathResolver({ sourceRootDir, encryptedRootDir })
    
    // calcAbsoluteSourceFilepath
    pathResolver.calcAbsoluteSourceFilepath('waw.txt') // => path.join(sourceRootDir, 'waw.txt')
    
    // calcAbsoluteEncryptedFilepath
    pathResolver.calcAbsoluteEncryptedFilepath('waw.txt') // => path.join(encryptedRootDir, 'waw.txt')
    
    // calcRelativeSourceFilepath
    pathResolver.calcRelativeSourceFilepath(path.join(sourceRootDir, 'waw.txt')) // => 'waw.txt'
    
    // calcRelativeEncryptedFilepath
    pathResolver.calcRelativeEncryptedFilepath(path.join(encryptedRootDir, 'waw.txt')) // => 'waw.txt'
  • FileCipherPathResolver

  • FileCipher

    import { ChalkLogger } from '@guanghechen/chalk-logger'
    import { AesCipherFactory } from '@guanghechen/helper-cipher'
    import { FileCipherFactory } from '@guanghechen/helper-cipher-file'
    
    const logger = new ChalkLogger({ flights: { colorful: false, date: false } })
    const cipherFactory = new AesCipherFactory()
    const fileCipherFactory = new FileCipherFactory({ cipherFactory, logger })
    const fileCipher = fileCipherFactory.fileCipher()
    
    // Encrypt multiple files and concatenate the encrypted contents.
    const encryptedContent: Buffer = await fileCipher.encryptFromFiles([sourceFilepath, sourceFilepath2, ...])
    
    // Encrypt multiple files and concatenate the decrypted contents.
    const decryptedContent: Buffer = await fileCipher.decryptFromFiles([encryptedFilepath1, encryptedFilepath2, ...])
    
    // Encrypt multiple files and write the concatenated encrypted contents into another file.
    await fileCipher.encryptFile([sourceFilepath1, sourceFilepath2, ...], outputFilepath)
    
    // Decrypt multiple files and write the concatenated decrypted contents into another file.
    await fileCipher.decryptFiles([encryptedFilepath1, encryptedFilepath2, ...], outputFilepath)
    
    // Decrypt file and write the encrypted content into another file.
    await fileCipher.encryptFiles([sourceFilepath1, sourceFilepath2, ...], outputFilepath)
    
    // Decrypt file and write the encrypted content into another file.
    await fileCipher.decryptFiles([encryptedFilepath1, encryptedFilepath2, ...], outputFilepath)

Overview

NameDescription
FileCipherEncrypt / Decrypt files.
FileCipherCatalogEncrypt / Decrypt files with catalog./home/lemon/ws/guanghechen/sora/packages/mac/src
FileCipherPathResolverResolve the relative / absolute filepaths.
calcFileCipherCatalogItem
diffFileCipherItems
areSameCatalogItem
normalizeSourceFilepath
calcMacFromFileCalc mac (Message Authentication Code) from fle.
calcFingerprintFromMacCalc fingerprint from mac.
calcFingerprintFromStringCalc fingerprint from literal string.
calcFingerprintFromFileCalc fingerprint from file.
6.0.0-alpha.16

4 months ago

6.0.0-alpha.17

4 months ago

6.0.0-alpha.15

5 months ago

6.0.0-alpha.14

5 months ago

6.0.0-alpha.12

5 months ago

6.0.0-alpha.13

5 months ago

6.0.0-alpha.11

5 months ago

6.0.0-alpha.10

5 months ago

6.0.0-alpha.9

5 months ago

6.0.0-alpha.8

5 months ago

6.0.0-alpha.5

5 months ago

6.0.0-alpha.6

5 months ago

6.0.0-alpha.7

5 months ago

6.0.0-alpha.3

6 months ago

6.0.0-alpha.4

5 months ago

6.0.0-alpha.0

6 months ago

6.0.0-alpha.1

6 months ago

6.0.0-alpha.2

6 months ago

5.0.9

7 months ago

5.0.8

8 months ago

5.0.7

9 months ago

5.0.6

9 months ago

5.0.5

9 months ago

5.0.4

9 months ago

5.0.3

10 months ago

5.0.2

10 months ago

5.0.10

7 months ago

5.0.11

7 months ago

5.0.12

6 months ago

5.0.1

12 months ago

5.0.0

12 months ago

5.0.0-alpha.3

1 year ago

5.0.0-alpha.2

1 year ago

4.7.2

1 year ago

4.7.1

1 year ago

4.7.4

1 year ago

4.7.3

1 year ago

5.0.0-alpha.1

1 year ago

5.0.0-alpha.0

1 year ago

4.7.0

1 year ago

4.6.5

1 year ago

4.6.4

1 year ago

4.6.3

1 year ago

4.6.2

1 year ago

4.6.1

1 year ago

4.6.0

1 year ago

4.5.0

1 year ago

4.4.3

1 year ago

4.4.2

1 year ago

4.4.1

1 year ago

4.4.0

1 year ago

4.3.0

1 year ago

4.2.2

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.3

1 year ago

4.1.2

1 year ago

4.1.1

1 year ago

4.1.0

1 year ago

4.0.0

1 year ago

4.0.0-alpha.8

1 year ago

4.0.0-alpha.7

1 year ago

4.0.0-alpha.6

1 year ago

4.0.0-alpha.5

1 year ago

4.0.0-alpha.4

1 year ago

4.0.0-alpha.3

1 year ago

4.0.0-alpha.2

1 year ago

4.0.0-alpha.1

1 year ago

4.0.0-alpha.0

1 year ago