claudeunmask 1.0.25 → 1.0.27
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/index.js +39 -19
- package/index.min.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* v 1.0.
|
|
1
|
+
/* v 1.0.27 */
|
|
2
2
|
function getMessageEncoding(message) {
|
|
3
3
|
return new TextEncoder().encode(message);
|
|
4
4
|
}
|
|
@@ -56,28 +56,33 @@
|
|
|
56
56
|
);
|
|
57
57
|
return getMessageDecoding(new Uint8Array(plaintextBuffer));
|
|
58
58
|
} catch (error) {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
console.log ("failed", key, bytesToBase64(ciphertext), error);
|
|
60
|
+
throw Error ("Failed to decrypt");
|
|
61
61
|
}
|
|
62
62
|
return "";
|
|
63
63
|
}
|
|
64
64
|
async function decrypt(inData, decryptionKey) {
|
|
65
65
|
var dailyKey = await window.prompt("Enter the daily key","crazy_string");
|
|
66
|
-
|
|
66
|
+
console.log ("decrypt: daily key", dailyKey);
|
|
67
67
|
var retVal = [];
|
|
68
68
|
var enc = new TextEncoder();
|
|
69
69
|
var [tmpPassword, salt, theIV] = decryptionKey.split("-");
|
|
70
|
-
|
|
70
|
+
console.log ("from MCP", decryptionKey, tmpPassword, salt, theIV);
|
|
71
71
|
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
try {
|
|
73
|
+
tmpPassword = await decryptThisData (base64ToBytes(tmpPassword), dailyKeyBinary, base64ToBytes(theIV));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.log ("failed to decrypt the key");
|
|
76
|
+
throw Error ("Failed to decrypt the key");
|
|
77
|
+
}
|
|
78
|
+
console.log ("secret:", tmpPassword);
|
|
74
79
|
const password = tmpPassword;
|
|
75
80
|
for (const curRec of inData) {
|
|
76
81
|
var tmpRec = {};
|
|
77
82
|
for (const [key, value] of Object.entries(curRec)) {
|
|
78
83
|
try {
|
|
79
84
|
if (typeof value === "string" && value.includes("m$k_")) {
|
|
80
|
-
|
|
85
|
+
console.log ("masked", value, curRec[key]);
|
|
81
86
|
var theData = base64ToBytes(curRec[key].replace ("m$k_", ""));
|
|
82
87
|
const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
|
|
83
88
|
tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
@@ -85,7 +90,7 @@
|
|
|
85
90
|
tmpRec[key] = value;
|
|
86
91
|
}
|
|
87
92
|
} catch (error) {
|
|
88
|
-
|
|
93
|
+
console.log ("error", error);
|
|
89
94
|
tmpRec[key] = "failed";
|
|
90
95
|
}
|
|
91
96
|
}
|
|
@@ -93,34 +98,49 @@
|
|
|
93
98
|
}
|
|
94
99
|
return retVal;
|
|
95
100
|
}
|
|
96
|
-
async function
|
|
97
|
-
|
|
98
|
-
var retVal =
|
|
101
|
+
async function unmaskData (inData, decryptionKey, dailyKey) {
|
|
102
|
+
console.log ("unmask: daily key", dailyKey);
|
|
103
|
+
var retVal = {};
|
|
104
|
+
retVal.data = [];
|
|
105
|
+
retVal.errorCount = 0;
|
|
106
|
+
retVal.unmaskCount = 0;
|
|
99
107
|
var enc = new TextEncoder();
|
|
100
108
|
var [tmpPassword, salt, theIV] = decryptionKey.split("-");
|
|
101
|
-
|
|
109
|
+
console.log ("from MCP", decryptionKey, tmpPassword, salt, theIV);
|
|
102
110
|
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
try {
|
|
112
|
+
tmpPassword = await decryptThisData (base64ToBytes(tmpPassword), dailyKeyBinary, base64ToBytes(theIV));
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.log ("failed to decrypt the key");
|
|
115
|
+
throw Error ("Failed to decrypt the key");
|
|
116
|
+
}
|
|
117
|
+
console.log ("secret:", tmpPassword);
|
|
105
118
|
const password = tmpPassword;
|
|
119
|
+
const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
|
|
106
120
|
for (const curRec of inData) {
|
|
107
121
|
var tmpRec = {};
|
|
108
122
|
for (const [key, value] of Object.entries(curRec)) {
|
|
109
123
|
try {
|
|
110
124
|
if (typeof value === "string" && value.includes("m$k_")) {
|
|
111
|
-
|
|
125
|
+
console.log ("masked", value, curRec[key]);
|
|
126
|
+
retVal.unmaskCount++;
|
|
112
127
|
var theData = base64ToBytes(curRec[key].replace ("m$k_", ""));
|
|
113
|
-
const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
|
|
114
128
|
tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
115
129
|
} else {
|
|
116
130
|
tmpRec[key] = value;
|
|
117
131
|
}
|
|
118
132
|
} catch (error) {
|
|
119
|
-
|
|
133
|
+
console.log ("error", error);
|
|
120
134
|
tmpRec[key] = "failed";
|
|
135
|
+
retVal.errorCount++;
|
|
121
136
|
}
|
|
122
137
|
}
|
|
123
|
-
retVal.push(tmpRec);
|
|
138
|
+
retVal.data.push(tmpRec);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (retVal.errorCount) {
|
|
142
|
+
console.log ("an error happened", (100 * retVal.errorCount / retVal.unmaskCount));
|
|
143
|
+
|
|
124
144
|
}
|
|
125
145
|
return retVal;
|
|
126
146
|
}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function getMessageEncoding(e){return new TextEncoder().encode(e)}function getMessageDecoding(e){return new TextDecoder().decode(e)}function base64ToBytes(e){let t=atob(e),a=new Uint8Array(t.length);for(let r=0;r<t.length;r++)a[r]=t.charCodeAt(r);return a}function bytesToBase64(e){let t=String.fromCharCode(...e);return btoa(t)}async function deriveKeyFromPassword(e,t){let a=getMessageEncoding(e),r=await crypto.subtle.importKey("raw",a,"PBKDF2",!1,["deriveKey"]),
|
|
1
|
+
function getMessageEncoding(e){return new TextEncoder().encode(e)}function getMessageDecoding(e){return new TextDecoder().decode(e)}function base64ToBytes(e){let t=atob(e),a=new Uint8Array(t.length);for(let r=0;r<t.length;r++)a[r]=t.charCodeAt(r);return a}function bytesToBase64(e){let t=String.fromCharCode(...e);return btoa(t)}async function deriveKeyFromPassword(e,t){let a=getMessageEncoding(e),r=await crypto.subtle.importKey("raw",a,"PBKDF2",!1,["deriveKey"]),o=await crypto.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:1e5,hash:"SHA-256"},r,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]);return o}async function decryptThisData(e,t,a){try{let r=await crypto.subtle.decrypt({name:"AES-GCM",iv:a},t,e);return getMessageDecoding(new Uint8Array(r))}catch(o){throw console.log("failed",t,bytesToBase64(e),o),Error("Failed to decrypt")}return""}async function decrypt(e,t){var a=await window.prompt("Enter the daily key","crazy_string");console.log("decrypt: daily key",a);var r=[];new TextEncoder;var[o,s,n]=t.split("-");console.log("from MCP",t,o,s,n);let i=await deriveKeyFromPassword(a,base64ToBytes(s));try{o=await decryptThisData(base64ToBytes(o),i,base64ToBytes(n))}catch(y){throw console.log("failed to decrypt the key"),Error("Failed to decrypt the key")}console.log("secret:",o);let l=o;for(let d of e){var c={};for(let[u,g]of Object.entries(d))try{if("string"==typeof g&&g.includes("m$k_")){console.log("masked",g,d[u]);var f=base64ToBytes(d[u].replace("m$k_",""));let h=await deriveKeyFromPassword(l,base64ToBytes(s));c[u]=await decryptThisData(f,h,base64ToBytes(n))}else c[u]=g}catch(p){console.log("error",p),c[u]="failed"}r.push(c)}return r}async function unmaskData(e,t,a){console.log("unmask: daily key",a);var r={};r.data=[],r.errorCount=0,r.unmaskCount=0,new TextEncoder;var[o,s,n]=t.split("-");console.log("from MCP",t,o,s,n);let i=await deriveKeyFromPassword(a,base64ToBytes(s));try{o=await decryptThisData(base64ToBytes(o),i,base64ToBytes(n))}catch(y){throw console.log("failed to decrypt the key"),Error("Failed to decrypt the key")}console.log("secret:",o);let l=o,d=await deriveKeyFromPassword(l,base64ToBytes(s));for(let c of e){var u={};for(let[g,f]of Object.entries(c))try{if("string"==typeof f&&f.includes("m$k_")){console.log("masked",f,c[g]),r.unmaskCount++;var h=base64ToBytes(c[g].replace("m$k_",""));u[g]=await decryptThisData(h,d,base64ToBytes(n))}else u[g]=f}catch(p){console.log("error",p),u[g]="failed",r.errorCount++}r.data.push(u)}return r.errorCount&&console.log("an error happened",100*r.errorCount/r.unmaskCount),r}
|