ipfs-encrypt
ipfs-encrypt copied to clipboard
A Node.js module for uploading and downloading encrypted folders to/from IPFS using AES-256-CBC encryption
IPFS-Encrypt
A Node.js module for uploading and downloading encrypted folders to/from IPFS using AES-256-CBC encryption.
Working
ipfs-encrypt
A Node.js module for uploading and downloading encrypted folders to/from IPFS using AES-256-CBC encryption.
Installation
npm install ipfs-encrypted
Requirements
To use the ipfs-encrypted
package, you need to have the following:
- Node.js installed on your computer. You can download it from the official Node.js website.
- A Web3 Storage token to authenticate your requests to the IPFS network. You can obtain a token by signing up for Web3 Storage.
Usage
- uploadEncryptionIpfs
- decryptFolderIpfs
- uploadToIpfs
- downloadFile
- encryptFolder
- decryptFolder
Upload with Encryption to Ipfs
uploadEncryptionIpfs(Web3Storagetoken, folderPath, password)
This function uploads a folder to IPFS and encrypts its contents using a password. The function takes three parameters:
-
Web3Storagetoken
: A Web3 Storage token used for authentication. -
folderPath
: The path to the folder that you want to upload and encrypt. -
password
: The password to use for encryption.
import { uploadEncryptionIpfs } from "ipfs-encrypted";
const token = "my_web3_storage_token";
const folderPath = "/path/to/folder";
const password = "my_password";
uploadEncryptionIpfs(token, folderPath, password)
.then((cid) => console.log(`Folder uploaded and encrypted with CID ${cid}`))
.catch((error) => console.error(`Error: ${error.message}`));
Download IPFS Decrypted Content
decryptFolderIpfs(Web3Storagetoken, cid, password, downloadLocation)
This function retrieves an encrypted folder from IPFS and decrypts its contents using a password. The function takes three parameters:
-
Web3Storagetoken
: A Web3 Storage token used for authentication. -
cid
: The CID of the encrypted folder on IPFS. -
password
: The password to use for decryption. -
downloadLocation
: Path of folder that content need to downloaded
import { decryptFolderIpfs } from "ipfs-encrypted";
const token = "my_web3_storage_token";
const cid = "Qm1234abcd";
const password = "my_password";
const downloadLocation = "/path/to/folder";
decryptFolderIpfs(token, cid, password, downloadLocation)
.then((folderPath) =>
console.log(`Folder decrypted and saved to ${folderPath}`)
)
.catch((error) => console.error(`Error: ${error.message}`));
Upload Folders to Ipfs without Encryption
uploadToIpfs(Web3Storagetoken, folderLocation)
This function uploads a folder to IPFS and returns the CID of the uploaded folder. The function takes two parameters:
-
Web3Storagetoken
: A Web3 Storage token used for authentication. -
folderLocation
: The path to the folder that you want to upload to IPFS.
import { uploadToIpfs } from "ipfs-encrypted";
const token = "my_web3_storage_token";
const folderLocation = "/path/to/folder";
uploadToIpfs(token, folderLocation)
.then((cid) => console.log(`Folder uploaded with CID ${cid}`))
.catch((error) => console.error(`Error: ${error.message}`));
Download IPFS content with CID
downloadFile(Web3Storagetoken, cid, downloadLocation)
This function downloads a file from IPFS and saves it to the current directory. The function takes two parameters:
-
Web3Storagetoken
: A Web3 Storage token used for authentication. -
cid
: The CID of the file to download from IPFS. -
downloadLocation
: Path of folder that content need to downloaded
import downloadFile from "ipfs-encrypted";
const token = "my_web3_storage_token";
const cid = "CID";
const downloadLocation = "/path/to/folder";
downloadFile(token, cid, downloadLocation)
.then((filePath) => console.log(`File downloaded and saved to ${filePath}`))
.catch((error) => console.error(`Error: ${error.message}`));
Encryption and Decryption using AES-256-CBC Algorithm
encryptFolder(folderPath, password)
This function recursively encrypts all files in a folder and its subfolders using AES-256-CBC encryption with the given password. The encrypted files are saved with a .encrypted extension. The function takes two parameters:
-
folderPath
: The path to the folder that you want to encrypt. -
password
: The password to use for encryption.
import { encryptFolder } from "ipfs-encrypted";
const folderPath = "/path/to/folder";
const password = "my_password";
encryptFolder(folderPath, password)
.then(() => console.log(`Folder encrypted successfully`))
.catch((error) => console.error(`Error: ${error.message}`));
decryptFolder(folderPath, password)
This function recursively decrypts all files in a folder and its subfolders that were previously encrypted with the encryptFolder function using AES-256-CBC encryption with the given password. The decrypted files are saved with their original file extensions. The function takes two parameters:
-
folderPath
: The path to the folder that you want to decrypt. -
password
: The password to use for decryption.
import { decryptFolder } from "ipfs-encrypted";
const folderPath = "/path/to/folder";
const password = "my_password";
decryptFolder(folderPath, password)
.then(() => console.log(`Folder decrypted successfully`))
.catch((error) => console.error(`Error: ${error.message}`));