You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
6.8 KiB
1 lines
6.8 KiB
(()=>{var h=class{};var w="%%\u{1F510}\u03B2 ",v="\u{1F510}\u03B2 ",D="%%\u{1F510}\u03B1 ",F="\u{1F510}\u03B1 ",B="%%\u{1F510} ";var f=[w,v,D,F,B],P=" \u{1F510}%%",C=" \u{1F510}",b=[P,C],p="\u{1F4A1}";var g=class{constructor(t){this.process(t)}process(t){var r,e;if(this.processedText=t,this.isEmpty=t.length===0,this.prefix=(r=f.find(n=>t.startsWith(n)))!=null?r:"",this.suffix=(e=b.find(n=>t.endsWith(n)))!=null?e:"",this.hasEncryptedPrefix=this.prefix.length>0,this.hasEncryptedSuffix=this.suffix.length>0,this.hasObsoleteEncryptedPrefix=this.prefix===B,this.containsEncryptedMarkers=[...f,...b].some(n=>t.includes(n)),this.canDecrypt=this.hasEncryptedPrefix&&this.hasEncryptedSuffix,this.canEncrypt=!this.hasEncryptedPrefix&&!this.containsEncryptedMarkers,this.canDecrypt){let n=this.parseDecryptableContent(t);n!=null?this.decryptable=n:this.canDecrypt=!1}}parseDecryptableContent(t){let r=new h;if(!this.hasEncryptedPrefix||!this.hasEncryptedSuffix)return null;this.hasObsoleteEncryptedPrefix?r.version=0:this.prefix==w||this.prefix==v?r.version=2:(this.prefix==D||this.prefix==F)&&(r.version=1);let e=t.substring(this.prefix.length,t.length-this.suffix.length);if([...f,...b].some(n=>e.includes(n)))return null;if(e.substring(0,p.length)==p){let n=e.indexOf(p,p.length);if(n<0)return null;r.hint=e.substring(p.length,n),r.base64CipherText=e.substring(n+p.length)}else r.base64CipherText=e;return r}};var S=new TextEncoder,U=new TextDecoder,O=1e3,K=S.encode("XHWnDAT6ehMVY2zD"),d=class{async deriveKey(t){let r=S.encode(t),e=await crypto.subtle.importKey("raw",r,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",hash:{name:"SHA-256"},iterations:O,salt:K},e,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(t,r){let e=await this.deriveKey(r),n=S.encode(t),o=crypto.getRandomValues(new Uint8Array(16)),s=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:o},e,n)),i=new Uint8Array(o.byteLength+s.byteLength);return i.set(o,0),i.set(s,o.byteLength),i}convertToString(t){let r="";for(let e=0;e<t.length;e++)r+=String.fromCharCode(t[e]);return r}async encryptToBase64(t,r){let e=await this.encryptToBytes(t,r);return btoa(this.convertToString(e))}stringToArray(t){let r=[];for(let e=0;e<t.length;e++)r.push(t.charCodeAt(e));return new Uint8Array(r)}async decryptFromBytes(t,r){try{let e=t.slice(0,16),n=t.slice(16),o=await this.deriveKey(r),s=await crypto.subtle.decrypt({name:"AES-GCM",iv:e},o,n);return U.decode(s)}catch(e){return null}}async decryptFromBase64(t,r){try{let e=this.stringToArray(atob(t));return await this.decryptFromBytes(e,r)}catch(e){return null}}};var u=class{constructor(t,r,e){this.vectorSize=t,this.saltSize=r,this.iterations=e}async deriveKey(t,r){let n=new TextEncoder().encode(t),o=await crypto.subtle.importKey("raw",n,"PBKDF2",!1,["deriveKey"]);return await crypto.subtle.deriveKey({name:"PBKDF2",hash:"SHA-512",salt:r,iterations:this.iterations},o,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(t,r){let e=crypto.getRandomValues(new Uint8Array(this.saltSize)),n=await this.deriveKey(r,e),s=new TextEncoder().encode(t),i=crypto.getRandomValues(new Uint8Array(this.vectorSize)),a=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:i},n,s)),l=new Uint8Array(i.byteLength+e.byteLength+a.byteLength);return l.set(i,0),l.set(e,i.byteLength),l.set(a,i.byteLength+e.byteLength),l}convertToString(t){let r="";for(let e=0;e<t.length;e++)r+=String.fromCharCode(t[e]);return r}async encryptToBase64(t,r){let e=await this.encryptToBytes(t,r);return btoa(this.convertToString(e))}stringToArray(t){let r=[];for(let e=0;e<t.length;e++)r.push(t.charCodeAt(e));return new Uint8Array(r)}async decryptFromBytes(t,r){try{let e,n;e=0,n=e+this.vectorSize;let o=t.slice(e,n);e=n,n=e+this.saltSize;let s=t.slice(e,n);e=n,n=void 0;let i=t.slice(e),a=await this.deriveKey(r,s),l=await crypto.subtle.decrypt({name:"AES-GCM",iv:o},a,i);return new TextDecoder().decode(l)}catch(e){return null}}async decryptFromBase64(t,r){try{let e=this.stringToArray(atob(t));return await this.decryptFromBytes(e,r)}catch(e){return null}}};var A={name:"AES-GCM",iv:new Uint8Array([196,190,240,190,188,78,41,132,15,220,84,211]),tagLength:128},m=class{async buildKey(t){let e=new TextEncoder().encode(t),n=await crypto.subtle.digest({name:"SHA-256"},e);return await crypto.subtle.importKey("raw",n,A,!1,["encrypt","decrypt"])}async encryptToBase64(t,r){let e=await this.buildKey(r),o=new TextEncoder().encode(t),s=new Uint8Array(await crypto.subtle.encrypt(A,e,o));return btoa(String.fromCharCode(...s))}stringToArray(t){let r=[];for(let e=0;e<t.length;e++)r.push(t.charCodeAt(e));return new Uint8Array(r)}async decryptFromBase64(t,r){try{let e=this.stringToArray(atob(t)),n=await this.buildKey(r),o=await crypto.subtle.decrypt(A,n,e);return new TextDecoder().decode(o)}catch(e){return null}}};var c=class{static BuildDefault(){return new u(16,16,21e4)}static BuildFromFileDataOrThrow(t){let r=c.BuildFromFileDataOrNull(t);if(r!=null)return r;throw new Error(`Unable to determine ICryptoHelper for File ver ${t.version}`)}static BuildFromFileDataOrNull(t){return t.version=="1.0"?new d:t.version=="2.0"?new u(16,16,21e4):null}static BuildFromDecryptableOrThrow(t){let r=c.BuildFromDecryptableOrNull(t);if(r!=null)return r;throw new Error(`Unable to determine ICryptoHelper for Decryptable ver ${t.version}`)}static BuildFromDecryptableOrNull(t){return t.version==0?new m:t.version==1?new d:t.version==2?new u(16,16,21e4):null}};var x=class{constructor(t,r,e){this.version="1.0";this.version=t,this.hint=r,this.encodedData=e}},I=class{static async encode(t,r,e){let o=await c.BuildDefault().encryptToBase64(e,t);return new x(I.DEFAULT_VERSION,r,o)}static async decrypt(t,r){return t.encodedData==""?"":await c.BuildFromFileDataOrThrow(t).decryptFromBase64(t.encodedData,r)}},E=I;E.DEFAULT_VERSION="2.0";var T=class{static encode(t){return JSON.stringify(t,null,2)}static decode(t){return t===""?new x(E.DEFAULT_VERSION,"",""):JSON.parse(t)}};var _=class{async decrypt(t,r){console.info("Trying the default decryption");let n=await c.BuildDefault().decryptFromBase64(t,r);if(n!=null)return n;console.info("Trying marked inplace feature decryption");let o=new g(t);if(o.decryptable!=null){let s=c.BuildFromDecryptableOrNull(o.decryptable);if(s!=null){let i=await s.decryptFromBase64(o.decryptable.base64CipherText,r);if(i!=null)return i}}for(let s=10;s>=0;s--){console.info("Trying non-marked inplace feature decryption","ver",s);let i={version:s,base64CipherText:t,hint:""},a=c.BuildFromDecryptableOrNull(i),l=await(a==null?void 0:a.decryptFromBase64(i.base64CipherText,r));if(l!=null)return l}console.info("Trying whole note feature decryption");try{let s=T.decode(t);console.debug(s);let i=c.BuildFromFileDataOrNull(s),a=await(i==null?void 0:i.decryptFromBase64(s.encodedData,r));if(a!=null)return a}catch(s){console.info(s)}return null}};window.$=new _;})();
|
|
|