I have a question regarding this vulnerability. I’d like to know what this actually means. Is it just some fantasy of GitHub Dependabot, or it is really something dangerous?
If I use it to encrypt my crypto private keys, will someone be able to decrypt them (without knowing my password)? Could you please explain in a simple manner what this vulnerability is in reality?
import CryptoJS from 'crypto-js';
export const encryptPrivateKey = (privateKey: string, password: string) => {
const privateKeyBytes = CryptoJS.enc.Hex.parse(privateKey);
const key = CryptoJS.PBKDF2(password, CryptoJS.SHA256(password), { keySize: 256 / 32 });
const ciphertext = CryptoJS.AES.encrypt(privateKeyBytes, key, { mode: CryptoJS.mode.ECB });
return String(ciphertext);
};
export const decryptPrivateKey = (encodedKey: string, password: string) => {
const key = CryptoJS.PBKDF2(password, CryptoJS.SHA256(password), { keySize: 256 / 32 });
const decryptedBytes = CryptoJS.AES.decrypt(encodedKey, key, { mode: CryptoJS.mode.ECB });
const decryptedHex = decryptedBytes.toString(CryptoJS.enc.Hex);
if (decryptedHex[0] == decryptedHex[1] && +decryptedHex[0] == 0) {
const decrypt = decryptedHex.substring(0, 1) + 'x' + decryptedHex.substring(2);
return decrypt;
}
return decryptedHex;
};
Will you be able to get the raw private key from the decrypted private key?
sEf9jM/BCXfQ94758EMFGcru3jut3U2vKhcZlyqL7xTU+/eeBkoJsQoiKQ6XQm0i