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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度