claudeunmask 1.0.19 → 1.0.21

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.
Files changed (3) hide show
  1. package/index.js +23 -27
  2. package/index.min.js +7 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* v 1.0.19 */
1
+ /* v 1.0.21 */
2
2
  function getMessageEncoding(message) {
3
3
  return new TextEncoder().encode(message);
4
4
  }
@@ -8,12 +8,12 @@
8
8
  }
9
9
 
10
10
  function base64ToBytes(base64) {
11
- const binary = atob(base64);
12
- const bytes = new Uint8Array(binary.length);
13
- for (let i = 0; i < binary.length; i++) {
14
- bytes[i] = binary.charCodeAt(i);
15
- }
16
- return bytes;
11
+ const binary = atob(base64);
12
+ const bytes = new Uint8Array(binary.length);
13
+ for (let i = 0; i < binary.length; i++) {
14
+ bytes[i] = binary.charCodeAt(i);
15
+ }
16
+ return bytes;
17
17
  }
18
18
 
19
19
  function bytesToBase64(bytes) {
@@ -32,20 +32,19 @@
32
32
  ['deriveKey']
33
33
  );
34
34
 
35
- const derivedKey = await crypto.subtle.deriveKey(
36
- {
37
- name: 'PBKDF2',
38
- salt: salt,
39
- iterations: 100000,
40
- hash: 'SHA-256',
41
- },
42
- keyMaterial,
43
- { name: 'AES-GCM', length: 256 },
44
- true,
45
- ['encrypt', 'decrypt']
46
- );
47
-
48
- return derivedKey;
35
+ const derivedKey = await crypto.subtle.deriveKey(
36
+ {
37
+ name: 'PBKDF2',
38
+ salt: salt,
39
+ iterations: 100000,
40
+ hash: 'SHA-256',
41
+ },
42
+ keyMaterial,
43
+ { name: 'AES-GCM', length: 256 },
44
+ true,
45
+ ['encrypt', 'decrypt']
46
+ );
47
+ return derivedKey;
49
48
  }
50
49
 
51
50
  async function decryptThisData(ciphertext, key, iv) {
@@ -60,24 +59,21 @@
60
59
  console.log ("failed", key, ciphertext);
61
60
  return "Failed to decrypt";
62
61
  }
63
-
64
62
  return "";
65
63
  }
66
64
  async function decryptData(inData, decryptionKey) {
67
65
  var retVal = [];
68
66
  var enc = new TextEncoder();
69
- var [password, salt, theIV] = decryptionKey.split("-");
70
-
67
+ var [tmpPassword, salt, theIV] = decryptionKey.split("-");
68
+ const password = tmpPassword.slice(2);
71
69
  for (const curRec of inData) {
72
70
  var tmpRec = {}
73
71
  for (const [key, value] of Object.entries(curRec)) {
74
72
  try {
75
73
  if (typeof value === "string" && value.includes("m$k_")) {
76
74
  var theData = base64ToBytes(curRec.secret_column.replace ("m$k_", ""));
77
- // theData = base64ToBytes(theData.split('-')[0]);
78
- // const theData = base64ToBytes(tmpData.split('-')[0]);
79
75
  const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
80
- console.log ("trying", password, salt, "space", theData);
76
+
81
77
  tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
82
78
  } else {
83
79
  tmpRec[key] = value;
package/index.min.js ADDED
@@ -0,0 +1,7 @@
1
+ function getMessageEncoding(message){return new TextEncoder().encode(message);}
2
+ function getMessageDecoding(buffer){return new TextDecoder().decode(buffer);}
3
+ function base64ToBytes(base64){const binary=atob(base64);const bytes=new Uint8Array(binary.length);for(let i=0;i<binary.length;i++){bytes[i]=binary.charCodeAt(i);}return bytes;}
4
+ function bytesToBase64(bytes){const binary=String.fromCharCode(...bytes);return btoa(binary);}
5
+ async function deriveKeyFromPassword(password,salt){const pwUtf8=getMessageEncoding(password);const keyMaterial=await crypto.subtle.importKey('raw',pwUtf8,'PBKDF2',false,['deriveKey']);const derivedKey=await crypto.subtle.deriveKey({name:'PBKDF2',salt:salt,iterations:100000,hash:'SHA-256',},keyMaterial,{name:'AES-GCM',length:256},true,['encrypt','decrypt']);return derivedKey;}
6
+ async function decryptThisData(ciphertext,key,iv){try{const plaintextBuffer=await crypto.subtle.decrypt({name:'AES-GCM',iv},key,ciphertext);return getMessageDecoding(new Uint8Array(plaintextBuffer));}catch(error){console.log("failed",key,ciphertext);return"Failed to decrypt";}return"";}
7
+ async function decryptData(inData,decryptionKey){var retVal=[];var enc=new TextEncoder();var[tmpPassword,salt,theIV]=decryptionKey.split("-");const password=tmpPassword.slice(2);for(const curRec of inData){var tmpRec={}for(const[key,value]of Object.entries(curRec)){try{if(typeof value==="string"&&value.includes("m$k_")){var theData=base64ToBytes(curRec.secret_column.replace("m$k_",""));const encryptionKey=await deriveKeyFromPassword(password,base64ToBytes(salt));tmpRec[key]=await decryptThisData(theData,encryptionKey,base64ToBytes(theIV));}else{tmpRec[key]=value;}}catch(error){tmpRec[key]="failed";}}retVal.push(tmpRec);}return retVal;}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudeunmask",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "claude unmask test",
5
5
  "main": "index.js",
6
6
  "scripts": {