Can I modify my existing JavaScript code to use PKCS5 padding in TripleDES encryption?

44 Views Asked by At

I need to encrypt a file using TripleDES, ECB and PKCS5 padding. I haven't found in forums or in stackoverflow any answer, due to the fact that they always use Pkcs7 on TripleDES, and i need Pkcs5. Right now this code doesn't work when i send it to the server for desencryption.

reader.onload = function (event) {
                    var fileData = event.target.result;

                    var key = "123456789";
                    var keyBytes = CryptoJS.enc.Utf8.parse(key);

                    var encryptedData = CryptoJS.TripleDES.encrypt(fileData, keyBytes, {
                        mode: CryptoJS.mode.ECB,
                        padding: CryptoJS.pad.Pkcs7
                    });

                    var fileEnc = new Blob([encryptedData]);

                    var a = document.createElement("a");
                    var url = window.URL.createObjectURL(fileEnc);
                    var filename = file.name + ".enc";
                    a.href = url;
                    a.download = filename;
                    a.click();
                    window.URL.revokeObjectURL(url);
                };
                reader.readAsDataURL(file);

Is there any way of doing the same code but with pkcs5? Or any JavaScript library which could help me use it instead of CryptoJS?

0

There are 0 best solutions below