-
Notifications
You must be signed in to change notification settings - Fork 67
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
Different output form AES 256 PHP and Delphi FMX #31
Comments
That should not differ. I have some suspicion...
|
Hi, Im using Cipher_FMX demo proyect. procedure TFormMain.ButtonEncryptClick(Sender: TObject); if not GetSettings(InputFormatting, OutputFormatting) then if ComboBoxCipherAlgorithm.ItemIndex >= 0 then
end I not sure where should i call Done Method, i guess this method does the encryption: |
Ok, done plays no role here as it seems. The answer was out of my head. |
what i did for simplicity, was to convert IV to HEX and put the hex value on (a7995d9813dd77ff698c2d1b0c2fe74a ) on EditInitVector.text edit, and on GetCipherAlgorithm function I modified a bit. so I can decode the base64 secret key, as follows: function TFormMain.GetCipherAlgorithm(var Cipher : TDECCipher):Boolean; result := false; // Find the class type of the selected cipher class and create an instance of it if TFormat_HEX.IsValid(RawByteString(EditInitVector.Text)) and
end result := true; |
here is the modified project. |
Thanks for providing the modified project. I try to look at it as soon as I can, but currently there's too much going on, like finalizing the new release and preparing my talk on EKON (https://entwickler-konferenz.de/tips-tricks-and-technics/kryptographiegrundlagen-am-beispiel-der-dec-delphi-encryption-compendium/). The problem most likely has to do with the way DEC handles padding, which I'm not really familiar with yet. That was designed by the original creator of the library, which I do not know personally. I know his successor though, but I doubt he did much on that part. |
Somebody (not me due to lack of time) tried to run yet test program provided but got an exception. The key length is too long. Is the key base 64 coded? |
The implementation of TNetEncoding Base64 in Delphi has a built in limit at which point it splits with a CRLF sequence - not sure if this is helpful ? We had an issue with a truncated encrypted value due to this. |
Thanks for adding the idea it might be related to line break handling in Delphi's Base64 implementation. |
@fastbike FYI If you manually create a TBase64Encoding instead of of using TNetEncoding.Base64... you can specify line length, including not splitting it up on a line at all. Also I have noticed in my 11.2 that there actually is a TNetEncoding.Base64String that doesn't split the base64 up into lines at all. |
Can somebody of you check if that splitting is the culprit? |
I have to encrypt/decrypt a string on AES 256 CBC, and I'm getting a shorter string compared wit PHP.
PHP Example:
https://gist.github.com/ezegg/8d54c98b8fbdce263409eabaf8afabe6
As you can see, string is "shorter" in Delphi.
here is the test string, Secret key and init vector
SECRET_KEY = "HPo7OLqB4Fkk4E2yGOtwqw8H5fHR9kNx67OR4g4UdlA=";
IV = "p5ldmBPdd/9pjC0bDC/nSg==";
Input String:
{"idServicio":79, "idProducto":209 , "referencia": "40425475190118187271", "montoPago": 9999, "telefono":"1111111111", "horaLocal":"20200401222821"}
Thank you
The text was updated successfully, but these errors were encountered: