AES 加密/解密 Delphi &PHP

2021-12-20 00:00:00 encryption aes php delphi lockbox-3

我的 Delphi 应用程序使用 TurboPower LockBox 3 使用 AES 256 加密明文信息.我现在想使用 PHP 解密此信息.但是 TurboPower LockBox 3 存在一些互操作性问题.

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.

请在此处查看 LockBox 3 作者的帖子以了解详细信息:

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

还有一篇关于 Stackoverflow 的类似帖子

And a similar post on Stackoverflow

Delphi 中的安全密钥对加密解决方案 &PHP?

在 LockBox 3 中,在加密期间,您设置密码.然后将此密码用作生成密钥和 iv 的种子.那么有没有人能够模仿 PHP 端的密钥生成方法?或者有什么方法可以让我获得 LockBox 3 生成的密钥/IV 并将其放入我的 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 ?

推荐答案

IV

如前所述,IV nonce 被添加到密文消息中.所以要在 PHP 端获取它,只需提取前 8 个字节即可.

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.

您需要决定共享密钥是密码字符串格式还是二进制密钥格式.symetric Key 类 (TSymetricKey) 有一个 SaveToStream() 方法,它按您的预期工作.TCodec 组件有一个 Key 属性,设置密码、链接模式和密码后即可使用.

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.

相关文章