douliao7354 2016-10-19 11:15 采纳率: 0%
浏览 81

关于RC4解密PHP(mcrypt)

I'm looking for anything about RC4 Decryption with decode the input using: Hexa

Lucky for me, I found PHP's mcrypt_encrypt.

I want to decrypt many cipher files with the same key. But, I had a problem with:

$iv_size = mcrypt_get_iv_size(MCRYPT_ARCFOUR, MCRYPT_MODE_STREAM); 
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); 
print (mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, $iv));

(And UTF-8 Vietnamese)

The result of echo $iv_size is 0.

Please help me, I don't know how I can fix it?

Key : Lyr1cjust4nct (key file .txt)

Mode: STREAM

Decode the input using: Hexa

Ciphertext: cipher.txt (Hexa)

http://pastebin.com/bmYcmU0J

  • 写回答

1条回答 默认 最新

  • douli1306 2016-10-19 13:47
    关注

    RC4 doesn't support IVs. You instead need to use a unique key for each message.

    RC4 has two big weaknesses that apply to your situation:

    • Using related keys is not secure. So you can't just concatenate a fixed key with a variable/unique IV. You'd need to use some kind of hashing scheme.
    • The beginning of the output is very biased, which leaks information about the ciphertext. So you need to throw away the beginning of the key-stream. I think throwing away 1024 bytes should take care of the biggest biases.

    RC4 doesn't include any integrity protection (MAC). So if an attacker manipulates the ciphertext, you'll run into problems.

    => Don't use RC4. Use AES in an authenticated mode such as GCM or by combining AES with a MAC using the encrypt-then-MAC principle.

    I strongly recommend using a high level library written by experts, since people get encryption wrong very often, even when using standard primitives like AES.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题