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.

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

报告相同问题?