📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

encrypt-image

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encrypt-image

encrypt and decrypt images using secret keys and public, private keys

1.0.8
latest
npm
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

How to use

Step - 1

Import the library

import { image } from "encrypt-image";

Step - 2

Generate keys using generateKeys() function and it will return public key , private key and symmetric key.

const keys = image.generateKeys();

Step - 3

use encrypt() function and pass the image , public key and symmetric key.

const encryptedImage = image.encrypt(image, keys.publicKey, keys.symmetricKey);

use decrypt function to get the original image , in this function just pass private key (keys.privateKey)

const encryptedData = fs.readFileSync('encrypted.bin');

const decryptedImage = image.decrypt(encryptedData,keys.privateKey);

can store decrypted image file using writeFileSync Function

fs.writeFileSync('decrepted.jpg',decryptedImage);

Example of encryption and decryption of image :

import { image } from "encrypt-image";
import fs from 'fs'

const keys = image.generateKeys();

const img = fs.readFileSync('image.jpg')

const encryptImage = image.encrypt(img, keys.publicKey, keys.symmetricKey);

const decryptedImage = image.decrypt(encryptedData,keys.privateKey);

fs.writeFileSync('dec.jpg',decryptedImage);

Example of encryption and decryption of Text :

import { text } from "encrypt-image";

const Keys = text.generateKeys();
const plaintext = "Hi this Encryption";
const encryptedText = text.encrypt(plaintext, Keys.publicKey);

console.log(encryptedText);

const decryptedText = text.decrypt(encryptedText,Keys.privateKey);

console.log(decryptedText);

Keywords

Hybrid Encryption of images

FAQs

Package last updated on 20 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts