I have read countless "encryption results differ between X & Y" but unfortunately have not been able to find a solution.
I am trying to duplicate the AES encryption of a string in Node based on some previously written encryption code in Swift using CocoaSecurity.
I have both of them returning base64 values, but unfortunately they are not the same.
FYI I added a "test" key, iv, and string as example, these are not the values I am using on my project.
let key = Data.init(base64Encoded: "DqviM6rMaYF3kHymVTiis7MH7agLcFqmDoX085K7AWs=")
let iv = Data.init(base64Encoded: "zur4lDpQk4tFaqnEUYKD9A==")
let aes256 = CocoaSecurity.aesEncrypt("Testing1!", key: key, iv: iv)
let result = aes256?.base64
// result = nmvqDhE43gRQ1B0EWCu7vg==
And in Node I have written the encryption (using the same key & iv ... I have triple checked) like this:
const key = Buffer.from('DqviM6rMaYF3kHymVTiis7MH7agLcFqmDoX085K7AWs=', 'base64');
const vector = Buffer.from('zur4lDpQk4tFaqnEUYKD9A==', 'base64');
const encryptTool = crypto.createCipheriv('aes256', key, vector);
const result = encryptTool.update("Testing1!", 'utf8', 'base64') + encryptTool.final('base64');
// results = FabfCtSAAuiZ9K93wcHXYA==
I know there can occasionally be differences in the padding between encryption implementations, but I tried adding encryptTool.setAutoPadding(false);
above and it would not run.
Are there any other options that could be set in the Node portion of this to ensure the same base64 string is returned?
Edited above to include key/vector, input string, and result