PluginProbe
CryptX / 4.2.1
CryptX v4.2.1
4.2.1 4.2.0 4.1.1 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 All 93 releases
cryptx / js / cryptx.min.js

cryptx.min.js in CryptX 4.2.1, at js/cryptx.min.js

1 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 !function(){const e=1e6,t=Math.min(parseInt(window.cryptxConfig?.iterations,10)||1e5,e),r=window.cryptxConfig?.keyLength||32,n=(window.cryptxConfig,window.cryptxConfig,{ALLOWED_PROTOCOLS:["http:","https:","mailto:"],MAX_URL_LENGTH:2048,ENCRYPTION_KEY_SIZE:32,IV_SIZE:16});class o{static getSecureRandomBytes(e){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("Secure random number generation not available");return crypto.getRandomValues(new Uint8Array(e))}static arrayBufferToBase64(e){const t=new Uint8Array(e);let r="";for(let e=0;e<t.byteLength;e++)r+=String.fromCharCode(t[e]);return btoa(r)}static base64ToArrayBuffer(e){const t=atob(e),r=new ArrayBuffer(t.length),n=new Uint8Array(r);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return r}static validateUrl(e){if("string"!=typeof e||0===e.length)return null;if(e.length>n.MAX_URL_LENGTH)return console.error("URL exceeds maximum length"),null;try{const t=new URL(e);if(!n.ALLOWED_PROTOCOLS.includes(t.protocol))return console.error("Protocol not allowed:",t.protocol),null;if("mailto:"===t.protocol){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.pathname))return console.error("Invalid email format in mailto URL"),null}return e}catch(e){return console.error("Invalid URL format:",e.message),null}}static escapeJavaScript(e){return"string"!=typeof e?"":e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}}class i{static originalDecrypt(e){if("string"!=typeof e||0===e.length)throw new Error("Invalid encrypted string");let t=0,r="mailto:",n=0;try{for(let o=0;o<e.length&&!(o+1>=e.length);o+=2){n=parseInt(e.charAt(o),10),isNaN(n)&&(n=0),t=e.charCodeAt(o+1),t>=8364&&(t=128);const i=t-n;if(i<0||i>1114111)throw new Error("Invalid character code during decryption");r+=String.fromCharCode(i)}return r}catch(e){throw new Error("Original decryption failed: "+e.message)}}static originalEncrypt(e){if("string"!=typeof e||0===e.length)throw new Error("Invalid input string");const t=e.replace(/^mailto:/,"");let r="";const n=["32","34","39","60","62","63","92","94","96","127"];try{for(let e=0;e<t.length;e++){let i,a,c=0;const s=20;do{if(c>=s){i=1,a=t.charCodeAt(e)+i;break}i=o.getSecureRandomBytes(1)[0]%4,a=t.charCodeAt(e)+i,a>=8364&&(a=128),c++}while(n.includes(a.toString())&&c<s);r+=i.toString()+String.fromCharCode(a)}return r}catch(e){throw new Error("Original encryption failed: "+e.message)}}}class a{static async deriveKey(n,o,i){const a=Number.isInteger(i)&&i>0?Math.min(i,e):t,c=new TextEncoder,s=await crypto.subtle.importKey("raw",c.encode(n),{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:o,iterations:a,hash:"SHA-256"},s,{name:"AES-GCM",length:8*r},!1,["encrypt","decrypt"])}static async encrypt(e,t){if("string"!=typeof e||"string"!=typeof t)throw new Error("Both plaintext and password must be strings");const r=new TextEncoder,i=o.getSecureRandomBytes(16),a=o.getSecureRandomBytes(n.IV_SIZE),c=await this.deriveKey(t,i),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:a},c,r.encode(e)),l=new Uint8Array(s),d=l.slice(0,-16),y=l.slice(-16),p=new Uint8Array(i.length+a.length+d.length+y.length);return p.set(i,0),p.set(a,i.length),p.set(d,i.length+a.length),p.set(y,i.length+a.length+d.length),o.arrayBufferToBase64(p.buffer)}static async decrypt(e,t,r){if("string"!=typeof e||"string"!=typeof t)throw new Error("Both encryptedData and password must be strings");try{const n=o.base64ToArrayBuffer(e),i=n.byteLength,a=16,c=16,s=16,l=i-a-c-s;if(i<a+c+s)throw new Error("Encrypted data too short");const d=n.slice(0,a),y=n.slice(a,a+c),p=n.slice(a+c,a+c+l),g=n.slice(-s),u=await this.deriveKey(t,new Uint8Array(d),r),f=new Uint8Array(p.byteLength+g.byteLength);f.set(new Uint8Array(p),0),f.set(new Uint8Array(g),p.byteLength);const w=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(y)},u,f);return(new TextDecoder).decode(w)}catch(e){throw new Error("Decryption failed: "+e.message)}}}async function c(e,t="default_key",r){if("string"==typeof e&&0!==e.length)try{let n;try{n=await a.decrypt(e,t,r)}catch(t){console.warn("Modern decryption failed, trying original algorithm"),n=i.originalDecrypt(e)}const c=o.validateUrl(n);if(!c)return void console.error("Invalid or unsafe URL detected");window.location.href=c}catch(e){console.error("Error during URL decryption and navigation:",e.message)}else console.error("Invalid encrypted URL provided")}function s(e){try{return i.originalDecrypt(e)}catch(e){return console.error("Legacy decryption failed:",e.message),null}}function l(e){const t=s(e);if(!t)return void console.error("Failed to decrypt URL");const r=o.validateUrl(t);r?window.location.href=r:console.error("Invalid or unsafe URL detected")}async function d(e,r="default_key"){if("string"!=typeof e||0===e.length)throw new Error("Valid email address required");if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))throw new Error("Invalid email format");const n=`mailto:${e}`,i=await a.encrypt(n,r);return`javascript:secureDecryptAndNavigate('${o.escapeJavaScript(i)}', '${o.escapeJavaScript(r)}', ${t})`}function y(e){if("string"!=typeof e||0===e.length)return console.error("Valid email address required"),"javascript:void(0)";try{const t=i.originalEncrypt(e);return`javascript:DeCryptX('${o.escapeJavaScript(t)}')`}catch(e){return console.error("Error generating handler:",e.message),"javascript:void(0)"}}function p(e){try{return i.originalEncrypt(e)}catch(e){return console.error("Error generating hash:",e.message),""}}const g="cryptx-link";function u(e){return!(!e||"function"!=typeof e.getAttribute)&&(e.classList&&"function"==typeof e.classList.contains?e.classList.contains(g):"string"==typeof e.className&&-1!==(" "+e.className+" ").indexOf(" "+g+" "))}async function f(e,t,r,n){if("string"!=typeof e||0===e.length)throw new Error("Missing or invalid data-cx payload");const o="string"==typeof r?r.trim().toLowerCase():"";if("legacy"===o)return i.originalDecrypt(e);if("undefined"==typeof crypto||!crypto||!crypto.subtle||"function"!=typeof crypto.subtle.importKey){if("secure"===o)throw new Error("Web Crypto API (crypto.subtle) is not available in this context");return i.originalDecrypt(e)}const c="string"==typeof t&&t.length>0?t:"default_key",s=parseInt(n,10);try{return await a.decrypt(e,c,s)}catch(t){if("secure"===o)throw t;return console.warn("CryptX: modern decryption failed, trying original algorithm"),i.originalDecrypt(e)}}async function w(e){if(!e)return;const t=function(e){let t=e,r=0;for(;t&&r<50;){if(u(t))return t;t=t.parentElement||t.parentNode||null,r++}return null}(e.target);if(!t)return;"function"==typeof e.preventDefault&&e.preventDefault();const r=t.getAttribute("data-cx"),n=t.getAttribute("data-cxk"),i=t.getAttribute("data-cxm"),a=t.getAttribute("data-cxi");try{const e=await f(r,n,i,a),t=o.validateUrl(e);if(!t)return void console.error("CryptX: invalid or unsafe URL detected, navigation aborted");window.location.href=t}catch(e){console.error("CryptX: could not resolve link target:",e&&e.message?e.message:e)}}function h(e){const t=e||("undefined"!=typeof document?document:null);return!(!t||"function"!=typeof t.addEventListener)&&(!t.__cryptxLinkHandlerAttached&&(t.addEventListener("click",w,!1),t.__cryptxLinkHandlerAttached=!0,!0))}"undefined"!=typeof document&&"function"==typeof document.addEventListener&&(h(document),"loading"===document.readyState&&document.addEventListener("DOMContentLoaded",function(){h(document)})),"undefined"!=typeof window&&(window.CryptX={secureDecryptAndNavigate:c,DeCryptX:l,DeCryptString:s,generateSecureEmailLink:d,generateDeCryptXHandler:y,generateHashFromString:p,handleCryptxLinkClick:w,initCryptxLinkHandler:h,SecureUtils:o,LegacyEncryption:i,SecureEncryption:a},window.secureDecryptAndNavigate=c,window.DeCryptX=l,window.DeCryptString=s,window.generateSecureEmailLink=d,window.generateDeCryptXHandler=y,window.generateHashFromString=p,window.handleCryptxLinkClick=w,window.initCryptxLinkHandler=h,window.SecureUtils=o,window.LegacyEncryption=i,window.SecureEncryption=a),"undefined"!=typeof module&&module.exports&&(module.exports={secureDecryptAndNavigate:c,generateSecureEmailLink:d,DeCryptX:l,DeCryptString:s,generateDeCryptXHandler:y,generateHashFromString:p,handleCryptxLinkClick:w,initCryptxLinkHandler:h,cryptxDecryptPayload:f,SecureEncryption:a,LegacyEncryption:i,SecureUtils:o})}();