claudeunmask 1.0.26 → 1.0.28
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 +51 -21
- 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.28 */
|
|
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,59 @@
|
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
console.log ("from MCP", decryptionKey, tmpPassword, salt, theIV);
|
|
110
|
+
var haveError = 0;
|
|
111
|
+
for (var ii= 0; ii<=2; ii++) { // try to decrypt the daily key and the add = until it works or we've added 2
|
|
112
|
+
console.log ("testing daily key: ", dailyKey);
|
|
113
|
+
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
114
|
+
try {
|
|
115
|
+
tmpPassword = await decryptThisData (base64ToBytes(tmpPassword), dailyKeyBinary, base64ToBytes(theIV));
|
|
116
|
+
// if we get here then we have a good daily key
|
|
117
|
+
haveError = 0;
|
|
118
|
+
break;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
haveError = 1;
|
|
121
|
+
dailyKey = dailyKey + '=';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (haveError) {
|
|
125
|
+
throw Error ("Failed to decrypt the key");
|
|
126
|
+
}
|
|
127
|
+
console.log ("secret:", tmpPassword);
|
|
105
128
|
const password = tmpPassword;
|
|
129
|
+
const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
|
|
106
130
|
for (const curRec of inData) {
|
|
107
131
|
var tmpRec = {};
|
|
108
132
|
for (const [key, value] of Object.entries(curRec)) {
|
|
109
133
|
try {
|
|
110
134
|
if (typeof value === "string" && value.includes("m$k_")) {
|
|
111
|
-
|
|
135
|
+
console.log ("masked", value, curRec[key]);
|
|
136
|
+
retVal.unmaskCount++;
|
|
112
137
|
var theData = base64ToBytes(curRec[key].replace ("m$k_", ""));
|
|
113
|
-
|
|
114
|
-
tmpRec[key] = '[dec]' + await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
138
|
+
tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
115
139
|
} else {
|
|
116
140
|
tmpRec[key] = value;
|
|
117
141
|
}
|
|
118
142
|
} catch (error) {
|
|
119
|
-
|
|
143
|
+
console.log ("error", error);
|
|
120
144
|
tmpRec[key] = "failed";
|
|
145
|
+
retVal.errorCount++;
|
|
121
146
|
}
|
|
122
147
|
}
|
|
123
|
-
retVal.push(tmpRec);
|
|
148
|
+
retVal.data.push(tmpRec);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (retVal.errorCount) {
|
|
152
|
+
console.log ("an error happened", (100 * retVal.errorCount / retVal.unmaskCount));
|
|
153
|
+
|
|
124
154
|
}
|
|
125
155
|
return retVal;
|
|
126
156
|
}
|
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}
|