!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;en.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+=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=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())&&c0?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(i0?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})}();