本文介绍了AES加密/解密Delphi& PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Delphi应用程序使用TurboPower LockBox 3来加密使用AES 256的明文信息。我现在想用PHP解密这个信息。
但是TurboPower LockBox 3具有一些互操作性问题。



请查看LockBox 3作者在这里的详细信息:





在Stackoverflow上有一个类似的帖子





在LockBox 3中,在加密过程中,您设置了一个密码。然后将此密码用作种子以生成密钥,iv。所以有人能够模仿PHP方面的关键生成方法吗?或者有什么办法可以让LockBox 3生成Key / IV,并将其放在我的PHP代码中,以便可以对文件进行解密?

解决方案

IV



如前所述,是加密密文。所以要在PHP端获取它,只需提取前8个字节。





您需要决定共享密钥是密码字符串格式还是二进制密钥格式。对称关键类(TSymetricKey)有一个SaveToStream()方法,它可以像您期望的那样工作。 TCodec组件具有Key属性,在您设置密码,链接模式和密码后,该属性将可用。



所有的方法都是自我记录的,几乎做了他们读的是什么,但是如果你需要一些演示代码,将一个密钥保存到流中,让我知道。


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 ?

解决方案

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.

这篇关于AES加密/解密Delphi& PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:58