Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result with migration from Crypto.AES.encrypt into node:crypto #481

Open
mkubasz opened this issue Jan 11, 2024 · 0 comments
Open

Comments

@mkubasz
Copy link

mkubasz commented Jan 11, 2024

I'm trying to find some information with migration but hard to find some details.

I have two methods:

const hashEncryptNew = (i: string): string => {
    const CryptoKeyNew = createHash('md5').update(String('supertest').trim()).digest('hex');
    const iv = Buffer.alloc(16, 0);
    const cipher = createCipheriv('aes-256-cbc', CryptoKeyNew, iv);
    const encrypted = cipher.update(i, 'utf8', 'base64') + cipher.final('base64');
    return encrypted;
};

const hashEncrypt = (i: string): string => {
    const CryptoKey = MD5(String('supertest').trim()).toString();
    const str = CryptoAES.encrypt(i, CryptoKey).toString();
    return str;
};

console.log(hashEncrypt("dog is here")) // U2FsdGVkX19qSDsTe47nHhUgCfCCZerzdVHPu+vL+2s=
console.log(hashEncryptNew("dog is here")) // pJEo0zcGtqD/1cOu5b5K/g==

There is a problem that in old code has default iv. I tried to find similarities but the result has different length too. Probably I miss something but I will be glad for some hints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant