node-libgenaro
Node.js library for encrypted file transfer on the GenaroNetwork network via bindings to libgenaro.
Example Usage
Install via npm:
npm install libgenaro
First setup the storj environment with authentication and encryption options:
const Environment = ; const libgenaro = bridgeUrl: 'http://111.111.111.111:8080' keyFile: `{ "address": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "crypto":{"ciphertext":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cipherparams":{"iv":"cccccccccccccccccccccccccccccccc"},"cipher":"aes-128-ctr", "kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","n":262144,"r":8, "p":1},"mac":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}, "id": "ffffffff-1111-2222-3333-444444444444", "version": 3 } ` passphrase: '123456';
Upload a file to a bucket:
const bucketId = '368be0816766b28fd5f43af5';const filePath = './test-upload.data'; const keyCtr = env;const index = keyCtrindex;const key = keyCtrkey;const ctr = keyCtrctr; const rsaKey = xxxxxx; // encrypted key with rsaconst rsaCtr = xxxxxx; // encrypted ctr with rsa const state = libgenaro;
Download a file from a bucket:
const bucketId = '368be0816766b28fd5f43af5';const fileId = '998960317b6725a3f8080c2b';const downloadFilePath = './test-download.data'; const key = xxxxxx; // the file encryption keyconst ctr = xxxxxx; // the file encryption ctr const state = libgenaro;
Once finished, you should call to zero and free memory holding encryption keys:
libgenaro;
API
Environment(options)
- A constructor for keeping encryption options and other environment settings, see available methods below
Methods available on an instance of Environment
:
getInfo(function(err, result) {})
- Get general API info`getBuckets(function(err, result) {})
- Get list of available bucketsdeleteBucket(bucketId, function(err, result) {})
- Delete a bucketrenameBucket(bucketId, function(err) {})
- Rename a bucketlistFiles(bucketId, function(err, result) {})
- List files in a bucketstoreFile(bucketId, fileOrData, isFilePath, options)
- Upload a file, return state objectstoreFileCancel(state)
- Cancel an uploadresolveFile(bucketId, fileId, filePath, options)
- Download a file, return state objectresolveFileCancel(state)
- Cancel a downloaddeleteFile(bucketId, fileId, function(err, result) {})
- Delete a file from a bucketgenerateEncryptionInfo(bucketId)
- Generate the key and ctr of AES-256-CTR for file encryption, and also the index related to the key and ctr, return undefined if faildecryptFile(filePath, key, ctr)
- Decrypt the undecrypted file use the key and ctr of AES-256-CTR, return the decrypted data if success, undefined if failencryptMeta(meta)
- Encrypt the meta use AES-256-GCM combined with HMAC-SHA512, return the encrypted meta if success, undefined if failencryptMetaToFile(meta, filePath)
- Encrypt the meta use AES-256-GCM combined with HMAC-SHA512 to filePathdecryptMeta(encryptedMeta)
- Decrypt the encryptedMeta, return the decrypted meta if success, undefined if faildecryptMetaFromFile(filePath)
- Decrypt the data in filePath, return the decrypted data if success, undefined if faildestroy()
- Zero and free memory of encryption keys and the environment