CodesInChaos answered my question with a URL. I want to redirect you to:
Encrypting file with checksum of the same file
-
24-06-2023 - |
문제
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:
- Generating the checksum of a file
- Encrypting file with checksum of the file
- Saving encrypted file on a server or disk
- Encrypting checksum with a RSA/ECC Public key
- Saving encrypted checksum on a server or disk
Decrypting:
- Decrypting checksum with RSA/ECC Private key
- 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
제휴하지 않습니다 StackOverflow