Так работает
const imageInput = document.getElementById('imageInput');
const encryptedTextDiv = document.getElementById('encryptedText');
const decryptionKeyInput = document.getElementById('decryptionKey');
const decryptButton = document.getElementById('decryptButton');
const decryptedImageDiv = document.getElementById('decryptedImage');
imageInput.addEventListener('change', (event) => {
const selectedImage = event.target.files[0];
const key = "123456";
const reader = new FileReader();
reader.onload = function(event) {
const encryptedImage = CryptoJS.AES.encrypt(event.target.result, key).toString();
localStorage.setItem('encryptedImage', encryptedImage);
encryptedTextDiv.textContent = encryptedImage.toString();
};
reader.readAsDataURL(selectedImage);
});
decryptButton.addEventListener('click', () => {
const decryptionKey = decryptionKeyInput.value;
const encryptedImage = localStorage.getItem('encryptedImage');
const decryptedBytes = CryptoJS.AES.decrypt(encryptedImage, decryptionKey).toString(CryptoJS.enc.Utf8);
// const decryptedImageBlob = new Blob([decryptedBytes], { type: 'image/jpeg' });
// const decryptedImageURL = URL.createObjectURL(decryptedImageBlob);
const img = document.createElement('img');
img.src = decryptedBytes;
decryptedImageDiv.innerHTML = '';
decryptedImageDiv.appendChild(img);
});