obscr 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,7 +43,7 @@ copyright 2022
43
43
 
44
44
  ```
45
45
 
46
- > :warning: **Only tested with png images**
46
+ > :warning: **Supports only png images**
47
47
 
48
48
  <br>
49
49
 
package/bin/utils/steg.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const fs = require("fs");
2
- const { loadImage, createCanvas } = require("canvas");
3
2
  const { get_hashed_order, str_to_bits, bits_to_str } = require("./utils");
3
+ const { PNG } = require("pngjs");
4
4
 
5
5
  const prepare_write_data = (data_bits, enc_key, encode_len) => {
6
6
  const data_bits_len = data_bits.length;
@@ -62,14 +62,11 @@ const write_lsb = (imgData, setdata) => {
62
62
  };
63
63
 
64
64
  exports.extractMessageFromImage = async (imagepath, encKey) => {
65
- let c, ctx, imgData;
65
+ let imgData;
66
66
 
67
67
  try {
68
- const img = await loadImage(imagepath);
69
- c = createCanvas(img.width, img.height);
70
- ctx = c.getContext("2d");
71
- ctx.drawImage(img, 0, 0, img.width, img.height);
72
- imgData = ctx.getImageData(0, 0, c.width, c.height);
68
+ const imageBuffer = fs.readFileSync(imagepath);
69
+ imgData = PNG.sync.read(imageBuffer);
73
70
  } catch (err) {
74
71
  return [false, err];
75
72
  }
@@ -94,14 +91,9 @@ exports.extractMessageFromImage = async (imagepath, encKey) => {
94
91
 
95
92
  exports.encodeMessageToImage = async (imagepath, msg, encKey) => {
96
93
  try {
97
- // const imageBuffer = fs.readFileSync(imagepath);
98
-
99
- const img = await loadImage(imagepath);
100
- const c = createCanvas(img.width, img.height);
101
- const ctx = c.getContext("2d");
102
- ctx.drawImage(img, 0, 0, img.width, img.height);
103
- // console.log(c.toDataURL);
104
- const imgData = ctx.getImageData(0, 0, c.width, c.height);
94
+ const imageBuffer = fs.readFileSync(imagepath);
95
+ const imgData = PNG.sync.read(imageBuffer);
96
+
105
97
  const encode_len = Math.floor(imgData.data.length / 4) * 3;
106
98
 
107
99
  // prepare data
@@ -113,9 +105,9 @@ exports.encodeMessageToImage = async (imagepath, msg, encKey) => {
113
105
  );
114
106
 
115
107
  const encryptedImgData = write_lsb(imgData, encryptedBitStream);
116
- ctx.putImageData(encryptedImgData, 0, 0);
117
- const encodedImageBuffer = c.toBuffer("image/png");
118
- fs.writeFileSync("encoded.png", encodedImageBuffer);
108
+ let buff = PNG.sync.write(encryptedImgData);
109
+
110
+ fs.writeFileSync("encoded.png", buff);
119
111
 
120
112
  return true;
121
113
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obscr",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Encrypt and hide your secure data",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -23,10 +23,10 @@
23
23
  "crypto"
24
24
  ],
25
25
  "dependencies": {
26
- "canvas": "^2.9.3",
27
26
  "chalk": "^4.1.2",
28
27
  "crypto-js": "^4.1.1",
29
28
  "inquirer": "^8.0.0",
29
+ "pngjs": "^6.0.0",
30
30
  "yargs": "^17.5.1"
31
31
  }
32
32
  }