Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
javascript aes files result input type readAsDataURL () correct url format that can be displayed in the browser

Javascript easily encrypted text files but in the case of images it does not give me result I already tried with the input type readAsDataURL () and it is great how in the data output once decrypted it shows the connection in the correct url format that can be displayed in the browser but I don't know how to convert the string into a file

<script type="module"> /* file encryption/decryption */
    document.addEventListener('DOMContentLoaded', function(event) {
        document.getElementById('src-file').onchange = function() {
            const file = this.files[0];
            document.querySelector('#progress').removeAttribute('value');
            const t1 = performance.now();
            var reader = new FileReader();
            reader.readAsText(file, 'utf-8');
            reader.onload = function() {
            document.querySelector('#progress').value = 100;
            var password = document.querySelector('#password').value;
            var bits = 256;
            var plaintext = reader.result;
            var ciphertext = AesCtr.encrypt(plaintext, password, bits);
            var blob = new Blob([ciphertext], { type: 'text/plain' });
            saveAs(blob, file.name + '.enc');
            document.querySelector('#progress').value = 0;
            const t2 = performance.now();
            const t = ((t2-t1)/1000).toFixed(3)+'s';
            document.querySelector('#decrypt-file-time').textContent = t;
            }
}

        document.querySelector('#enc-file').onchange = function() {
            const file = this.files[0];
            document.querySelector('#progress').removeAttribute('value');
            const t1 = performance.now();
            var reader = new FileReader();
            reader.readAsText(file, 'iso-8859-1');
            reader.onload = function() {
            document.querySelector('#progress').value = 100;
            var password = document.querySelector('#password').value;
            var bits = 256;
            var ciphertext = reader.result;
            var plaintext = AesCtr.decrypt(ciphertext, password, bits);
            var blob = new Blob([plaintext], {type: 'application/octet-stream' });
            saveAs(blob, file.name.replace(/\.enc$/,''));
            document.querySelector('#progress').value = 0;
            const t2 = performance.now();
            const t = ((t2-t1)/1000).toFixed(3)+'s';
            document.querySelector('#decrypt-file-time').textContent = t;
            }           

        }
       
    });
</script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!