第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何用 Java 加密用 PHP 解密?

如何用 Java 加密用 PHP 解密?

臨摹微笑 2023-06-04 17:08:37
我有一個遺留腳本,它已經將加密數據保存到數據庫中。加密/解密是用 Java 以下代碼完成的。public class StringEncrypter {    Cipher ecipher;    Cipher dcipher;    /**     * Constructor used to create this object. Responsible for setting and     * initializing this object's encrypter and decrypter Chipher instances     * given a Pass Phrase and algorithm.     *      * @param passPhrase     *            Pass Phrase used to initialize both the encrypter and     *            decrypter instances.     */    public StringEncrypter(String passPhrase) {        // 8-bytes Salt        byte[] salt = { (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,                (byte) 0x56, (byte) 0x34, (byte) 0xE3, (byte) 0x03 };        // Iteration count        int iterationCount = 19;        try {            KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt,                    iterationCount);            SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES")                    .generateSecret(keySpec);            ecipher = Cipher.getInstance(key.getAlgorithm());            dcipher = Cipher.getInstance(key.getAlgorithm());            // Prepare the parameters to the cipthers            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,                    iterationCount);            ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);            dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);這會像這樣將一個字符串放入數據庫RX0qxgKAKmjQmS9xjNtFnw==我需要能夠使用 PHP 解密這些數據。我嘗試使用 github 中的這個腳本: https: //github.com/KevinBusse/PBEWithMD5AndDES但只能得到一個輸出bad magic number這可能嗎?如果是這樣,任何方向將不勝感激!
查看完整描述

1 回答

?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

如果從 Java 代碼中獲取以下設置,則可以使用 Github 代碼進行解密:

  • 鹽(十六進制):A99BC8325634E303

  • 迭代:19

例子:

Passphrase:? ? ? ? ? ? ? ? ? ? MyPassphraseXYZ

Plaintext:? ? ? ? ? ? ? ? ? ? ?The quick brown fox jumps over the lazy dog

Ciphertext from the Java code: xWnsqJJ4pqWTrm8kIwfyw1djD4lu0zig0wnohS+EtwDvHBgEP/BS25qyaE+QEdxd

可以使用 PHP 代碼解密密文,如下所示:


$data = "xWnsqJJ4pqWTrm8kIwfyw1djD4lu0zig0wnohS+EtwDvHBgEP/BS25qyaE+QEdxd";

$keystring = "MyPassphraseXYZ";

$salt = "A99BC8325634E303";

$iterationsMd5 = 19;?

$decrypted = PbeWithMd5AndDes::decrypt($data, $keystring, $salt, $iterationsMd5);

print($decrypted . "\n");

必須考慮以下因素:PbeWithMd5AndDes已經過時并且已經存在多年,Github 代碼本身使用了其他已棄用的函數,例如mcrypt_module_XXX()and?mcrypt_generic_YYY(),因此此代碼只能在 PHP < 7.2 的情況下執(zhí)行。在 PHP 7.1 中,顯示棄用警告。只有 PHP < 7.1 的代碼可以在沒有警告的情況下執(zhí)行。總而言之,算法和代碼都是不安全的。



查看完整回答
反對 回復 2023-06-04
  • 1 回答
  • 0 關注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號