AES Encrypt/Decrypt Delphi & PHP

僤鯓⒐⒋嵵緔 提交于 2019-12-17 19:37:23

问题


My Delphi application uses TurboPower LockBox 3 to encrypt a plaintext information using AES 256. I now want to decrypt this information using PHP. But TurboPower LockBox 3 has some interoperability issues.

Please check the post by LockBox 3 author here for details :

http://lockbox.seanbdurkin.id.au/tiki-view_forum_thread.php?comments_parentId=363&topics_offset=1

And a similar post on Stackoverflow

Secure keypair encryption solution in Delphi & PHP?

In LockBox 3, during encryption, you set a password. This password is then used as a seed to generate the key and iv. So has anyone been able to mimic the key generation method on PHP side ? Or is there any way i can get the Key/IV being generated by LockBox 3 and put it in my PHP code so the file can be decrypted ?


回答1:


IV

As stated to you before, the IV nonce is prepended to the ciphertext message. So to obtain it on the PHP side, simply extract the first 8 bytes.

Keys

You need to decide if the shared secret is in password-string format or binary key format. The symetric Key class (TSymetricKey) has a method SaveToStream(), which works as you would expect it to. The TCodec component has a Key property, which will be available after you set the cipher, chaining mode and password.

All of the methods are self-documenting and do pretty much what they read like, however if you need some demo code, saving a key to a stream, let me know.



来源:https://stackoverflow.com/questions/12138244/aes-encrypt-decrypt-delphi-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!