문제

How safe is it to encrypt your files with a cipher like AES-256-CBC with the checksum of the same file, used as a key? Is that a risk, or is it safe?

Like this steps:

  1. Generating the checksum of a file
  2. Encrypting file with checksum of the file
  3. Saving encrypted file on a server or disk
  4. Encrypting checksum with a RSA/ECC Public key
  5. Saving encrypted checksum on a server or disk

Decrypting:

  1. Decrypting checksum with RSA/ECC Private key
  2. Using checksum to decrypt file

Are my ideas safe?

다른 팁

for encripting an file to checksum is more or less easy; you can use the library like cripto-js

npm install cripto-js

And if you use typescript

npm install @types/criptojs

After that you already install this library, you must convert the file (image) to MD5 and then, convert the STRING generate for MD5 to base64.

You can run some this:

new Promise((resolve, reject) => {
  const reader = new FileReader();
  reader.readAsDataURL(file);
  reader.onload = (event: any) => {
    let binari = event.target.result;
    let md5 = criptoJS.MD5(binari).toString();
    const encodedWord = criptoJS.enc.Utf8.parse(md5);
    const encoded = criptoJS.enc.Base64.stringify(encodedWord);
    resolve(reader.result);
  };
  reader.onerror = error => reject(error);
});

and yes, i am run typescript.

I hope this it work for you. :) happy coding

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top