Tuesday, 17 December 2019

migrate createCipher et createCipheriv

I just moved to node 12.13 and I have some issue with crypto.createDecipher and crypto.createCipher

First I have deprecation warnings when I am using the two functions.

    const encodeString = (value, password) => new Promise((resolve, reject) => {
        const cipher = crypto.createCipher('aes192', password);
        let encrypted = '';
        cipher.on('readable', () => {
            const data = cipher.read();
            if (data) encrypted += data.toString('hex');
        });
        cipher.on('end', () => resolve(encrypted));

        cipher.write(value);
        cipher.end();
    });

    const decodeString = (encrypted, password) => new Promise((resolve, reject) => {
        const decipher = crypto.createDecipher('aes192', password);
        let decrypted = '';
        decipher.on('readable', () => {
            const data = decipher.read();
            if (data) decrypted += data.toString('utf8');
        });
        decipher.on('end', () => resolve(decrypted));

        decipher.write(encrypted, 'hex');
        decipher.end();
    });

I am looking for a way to migrate to createCipheriv and createDecipheriv but I can not find how to convert my password into key and iv



from migrate createCipher et createCipheriv

No comments:

Post a Comment