På sendfilesencrypted.com bryr vi oss om säkerheten för dina filer och vi vill att din upplevelse av att dela filer online ska vara och känna sig trygg.
Det är därför vi har implementerat gratis filkrypteringsfunktion.
Alla filer som du delar i Sendfilesencrypted.com krypteras innan de laddas upp till våra servrar, detta lägger till ett lager av säkerhet till varje fil som du delar, vilket förhindrar någon person eller hot från att komma åt dem.
På samma sätt dekrypteras alla dina filer i din webbläsare med lösenordet du angav när du laddade upp dem, detta säkerställer att om en angripare kommer åt dina filer kommer de att vara helt krypterade.
Så här krypterar vi dina filer innan de laddas upp och lagras på våra servrar.
Koden delar upp dina filer i flera små filer, varje bit krypteras med lösenordet du använde för att ladda upp dem och en unik kod för varje grupp av filer, detta ger ännu större säkerhet till dina filer. Efter denna process laddas varje bit av krypterad fil upp och lagras på vår server. Detta säkerställer att även vi, utvecklarna, inte kan komma åt dina filer.
/* | |
In this code you will find how I encrypt files (using CryptoJS) before uploading to the server, this is the steps I follow: | |
1. Calculate the size of all the files I want to upload, I will use this number to stop my recursive function | |
2. I slice every file in chunks of max 5MB, if the final value of chunkEnd is equals to the current file size then I jump to the next file passing the new index as indexFile + 1 | |
3. I read the file slice using FileReader, then I start the encryption of the arrayBuffer content, passing the password the user provide. | |
4. I create a new Blob using the encrypted string and pass it to my custom Ajax function to upload it to the server, once the encrypted chunk is stored I call the recursive function again. | |
*/ | |
var chunkStart = 0; | |
var chunkEnd = 0; | |
var chunkCounter = 0; | |
var files = $(this)[0].files; | |
var totalSize = files.map( | |
function (item) { | |
return item.size | |
} | |
).reduce( | |
function (a, b) { | |
return a + b | |
} | |
); | |
uploadChunk(totalSize, 0, chunkStart, chunkEnd, chunkCounter); | |
// I will use this function to encrypt and upload every file slice | |
function uploadChunk(totalSize, fileIndex, chunkStart, chunkEnd, chunkCounter) { | |
if (fileIndex >= files.length) { | |
return; | |
} | |
var currentFile = files[fileIndex]; | |
var chunkSize = 6000000; | |
var fileSize = currentFile.size; | |
if (chunkEnd >= fileSize) { | |
return uploadChunk(totalSize, fileIndex + 1, 0, 0, 0); | |
} | |
chunkEnd = Math.min(chunkStart + chunkSize, fileSize); | |
var reader = new FileReader(); | |
reader.onload = function () { | |
var secret_key = CryptoJS.PBKDF2( | |
password, | |
CryptoJS.enc.Hex.parse(`${file_key}`), | |
{ | |
keySize: 512 / 32, | |
iterations: 20000 | |
} | |
); | |
var ivString = generateRandom(chars=120); | |
var iv = CryptoJS.enc.Hex.parse(`${ivString}`); | |
var wordArray = CryptoJS.lib.WordArray.create(reader.result); | |
var encrypted = CryptoJS.AES.encrypt(wordArray, secret_key, { | |
iv: iv | |
}).toString(); | |
var encryptedFile = new Blob([`${ivString}:${encrypted}`]); | |
// PromiseRequestFunction is a custom function I use to make ajax requests, I'm passing the blob files as parameter | |
var p = PromiseRequestFunction( | |
... | |
[encryptedFile] | |
); | |
p.then( | |
function () { | |
chunkStart += chunkSize; | |
chunkCounter += 1; | |
uploadChunk(totalSize, fileIndex, chunkStart, chunkEnd, chunkCounter); | |
}, | |
function () { | |
} | |
); | |
} | |
reader.readAsArrayBuffer(currentFile.slice(chunkStart, chunkEnd)); | |
} |
Nu ska jag visa dig hur vi dekrypterar dina filer.
Kom ihåg att varje originalfil förvandlades till många bitar av krypterade filer, som är de som lagras på vår server. Varje del laddas ner i webbläsaren och sedan används lösenordet du angav och den unika koden för filblocket för att kunna dekryptera varje del som kommer att kopplas till de många andra dekrypterade delarna av din originalfil och sedan skapa och ladda ner originalfil.
/* | |
In this code you will find how I decrypt blob files (using CryptoJS) | |
1. I need the filename and get the blobURLs (for this example I will be using a hardcoded blobURLs, but in my case I'm getting that info from a previous ajax call) | |
// I start the recursive function. Note the the first paramater will contains the decrypted blobs. | |
2. I check if the index is greated than my blobURLs length, so I can know when to stop the recursive function and create the download link. | |
3. I get the blob file using XMLHttpRequest and passing the blobURL. | |
4. I read the blob content using FileReader, note that I'm using reader.readAsText because I'm getting a base64 text. | |
5. I decrypt the blob text content, using the password passed by the user. | |
6. I parse the wordArray and create a new Blob with the result that is stored in the blobs array and I call the recursive function again. | |
*/ | |
var filename = 'my_awesome_picture.png'; | |
var blobURLS = ['https://sfo.to/blob_1', 'https://sfo.to/blob_2', ...] | |
getBlob([], blobURLs, 0, filename); | |
function getBlob(blobs, urls, index, filename) { | |
if (index >= urls.length) { | |
var blob = new Blob(blobs); | |
var url = window.URL.createObjectURL(blob); | |
var a = document.createElement('a'); | |
a.href = url; | |
a.download = filename; | |
a.click(); | |
} else { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
if (this.readyState === 4 && this.status === 200) { | |
var reader = new FileReader(); | |
reader.onload = function () { | |
var secret_key = secret_key = CryptoJS.PBKDF2( | |
password, | |
CryptoJS.enc.Hex.parse(`${file_key}`), | |
{ | |
keySize: 512 / 32, | |
iterations: 20000 | |
} | |
); | |
var encryptedParts = reader.result.split(':'); | |
var iv = CryptoJS.enc.Hex.parse(`${encryptedParts[0]}`); | |
encryptedParts.shift(); | |
var decrypted = CryptoJS.AES.decrypt(encryptedParts.join(), secret_key, { | |
iv: iv | |
}); | |
var typedArray = convertWordArrayToUint8Array(decrypted); | |
blobs.push(new Blob([typedArray])); | |
getBlob(blobs, urls, index + 1, filename); | |
}; | |
reader.readAsText(this.response); | |
} | |
} | |
xhr.open('POST', `${urls[index]}`); | |
xhr.responseType = 'blob'; | |
xhr.send(); | |
} | |
} | |
function convertWordArrayToUint8Array(wordArray) { | |
var arrayOfWords = wordArray.hasOwnProperty("words") ? wordArray.words : []; | |
var length = wordArray.hasOwnProperty("sigBytes") ? wordArray.sigBytes : arrayOfWords.length * 4; | |
var uInt8Array = new Uint8Array(length), index = 0, word, i; | |
for (i = 0; i < length; i++) { | |
word = arrayOfWords[i]; | |
uInt8Array[index++] = word >> 24; | |
uInt8Array[index++] = (word >> 16) & 0xff; | |
uInt8Array[index++] = (word >> 8) & 0xff; | |
uInt8Array[index++] = word & 0xff; | |
} | |
return uInt8Array; | |
} |
Gillar du det du läser? Skicka filer krypterade nu