在 PHP 中实现这个 Java 密码加密算法
我正在尝试用 PHP 实现 Funambol 移动同步服务器中使用的密码加密算法,但由于我来自非 Java 背景,所以我遇到了困难。代码本身看起来很简单:
encryptionKey = "Omnia Gallia in tres partes divida est";
byte[] newValue = new byte[24];
System.arraycopy(encryptionKey, 0, newValue, 0, 24);
encryptionKey = newValue;
KeySpec keySpec = new DESedeKeySpec(encryptionKey);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESEde");
Cipher cipher = Cipher.getInstance("DESEde");
SecretKey key = keyFactory.generateSecret(keySpec);
cipher.init(Cipher.ENCRYPT_MODE, key);
cipherBytes = cipher.doFinal(plainBytes);
我不一定要寻找完整的解决方案,而是寻找可以在 PHP 方面使用的内容的指针。 mcrypt 可以处理这个问题吗?处理到什么程度?我还需要什么?这在 PHP 中可行吗?
好奇的是:我正在构建 Funambol 服务器的接口,并且我希望能够使用 PHP 从接口本身添加用户。
I'm trying to implement a password encryption algorithm used in Funambol mobile sync server in PHP but I'm having hard time as I come from a non-Java background. The code itself seems simple:
encryptionKey = "Omnia Gallia in tres partes divida est";
byte[] newValue = new byte[24];
System.arraycopy(encryptionKey, 0, newValue, 0, 24);
encryptionKey = newValue;
KeySpec keySpec = new DESedeKeySpec(encryptionKey);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESEde");
Cipher cipher = Cipher.getInstance("DESEde");
SecretKey key = keyFactory.generateSecret(keySpec);
cipher.init(Cipher.ENCRYPT_MODE, key);
cipherBytes = cipher.doFinal(plainBytes);
I'm not necessarily looking for a complete solution, rather pointers on what I can use on PHP's side. Can mcrypt handle this and to what extent? What else do I need? Is this even doable in PHP?
To the curious: I'm building an interface to the Funambol server and I'd like to be able to add users from the interface itself using PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
终于解决了,在这里发帖以防有人需要使用 PHP 加密或解密 Funambol 的密码:
Finally got it solved, posting here in case someone ever needs to encrypt or decrypt passwords for Funambol using PHP:
这可能就是您想要的:
请注意,由于 3DES 加密/解密数据块的方式,我使用数据加密
$sDataSize
。This may be what you want:
Notice I encrypt
$sDataSize
with the data because of the way 3DES encypts/decrypts blocks of data.