duan33360 2012-05-25 01:28
浏览 31
已采纳

如何解密PHP页面中的三重DES字符串?

I was hoping someone could help a non-PHP developer with an example of how to decrypt a Triple DES URL Encoded string (e.g. passed to the page in a querystring variable named "q").

The key is 24 bit and the intialization vector is 8 bit.

In C# the original data is:

  1. UTF-8 encoded as a byte array
  2. Encrypted with the key and IV
  3. Encoded as a Base 64 string
  4. URL encoded as a string

...

byte[] rawData;
TripleDES tripleDESalg = TripleDES.Create();
rawData = UTF8Encoding.UTF8.GetBytes(message);
ICryptoTransform cTransform = tripleDESalg.CreateEncryptor(key, IV);
byte[] resultArray = cTransform.TransformFinalBlock(rawData, 0, rawData.Length);
tripleDESalg.Clear();
encryptedText = Convert.ToBase64String(resultArray);

...

In a PHP page, I can't really find examples on how to these steps together:

  1. Decode the URL encoded string in the querystring variable "q"
  2. Decode the Base 64 encoded string (e.g. base64_decode)
  3. Decrypt the value using the same key and iv that was used to encrypt it (assume you control the encrypting and decrypting and both system know what the key and iv are)
  4. Print/echo the output

  • 写回答

1条回答 默认 最新

  • dongxiandi8313 2012-05-25 01:35
    关注

    Get value from query string

    $string = $_REQUEST['q'];

    URL Decode

    urldecode

    Base 64 Decode

    base64_decode

    Decryption

    Use mcrypt_decrypt.

    For the first parameter, you pass in the cipher (List of Ciphers), which, in your case, would be MCRYPT_DES.

    The remaining parameters would be the ciphertext, key, iv etc.

    The PHP manual is exhaustive. Use it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页