Open China-xiaoFang opened 1 year ago
@Net-18K Aha!
First, note that aes_encrypt_data
(the output from BouncyCastle's DoFinal(...)
) contains aes_encrypt_auth_tag
. This is consistent with most crypto libraries as the tag is usually appended to the ciphertext. You'll want to trim that off if you want them separate.
Second, I looked at some test vectors and used standard test vectors.
$ dotnet run
ciphertext:
Wo3vLwyeU/H3XXhTZZ4qIO6ysiqv3mQZoFirT290a/QPwMO3gPJERS2j6/HF2CzeokGJlyAO+C5Ern4/pEqCZu4cjrDItdTPWunxmg==
Auth Tag:
pEqCZu4cjrDItdTPWunxmg==
(these match the values when converted hex to base64: Wo3vLwyeU/H3XXhTZZ4qIO6ysiqv3mQZoFirT290a/QPwMO3gPJERS2j6/HF2CzeokGJlyAO+C5Ern4/
and pEqCZu4cjrDItdTPWunxmw==
.
$ nodejs ./index.js
{"iv":"kxMiXfiEBuVVkJxa/1Jpqmp6lThTT32h5MMD0qMYpyjDwMlRVoCVOfzw4kKaa1JUFq7b9aDealemN7Ob","data":"HXm3r5NtevjyMEJUtnt/EPAVQw9GuVhQpIuRadF7vUUUScCLoU9mmkVMmpXI1cudTWVA4E6r5hG+a0c6","authtag":"pwRUJ5co3gzVwmkzJC4beg=="}
This shows that the issue lies on the NodeJS side.
I'm not quite sure why, though. The inputs look OK from my PoV, likely there's something with the integration with OpenSSL.
I'm on the following NodeJS version:
$ node --version
v18.13.0
(with OpenSSL 3.0.10).
Hope this helps!
Below is my NodeJS code.
Below is my C# code.
I have been troubled by this problem for many days. I hope you can help me figure out where the problem occurred and the resulting encrypted data is inconsistent.