【问题标题】:Decrypting with libsodium with a 64-bit nonce使用 64 位随机数使用 libsodium 解密
【发布时间】:2015-09-29 18:43:24
【问题描述】:

我建立了一个站点,它从表单中获取数据并使用 libsodium for php 对其进行加密。由于服务器上发生的一些事情,CRYPTO_BOX_NONCEBYTES 变量以某种方式返回 64 而不是 24。我们现在有几个使用 libsodium 加密的文件,使用的随机数大小为 64,我们也有相关的随机数文件。有什么办法可以解密吗?

换句话说,我有一个使用 64 位随机数加密的文件。当我尝试使用相同的 64 位随机数对其进行解密时,它会失败并出现以下错误:

PHP Fatal error:  crypto_box_open(): nonce size should be CRYPTO_BOX_NONCEBYTES long in /data/www/docroot/filename.php on line 42

【问题讨论】:

    标签: php encryption libsodium


    【解决方案1】:

    当然,给定一个有效的密文、密钥对和您的 64 字节随机数,您应该能够做到这一点:

    // Keep increasing this from 0 to 39 to see if you can grab the 
    // correct slice of the nonce string:
    $try = 0;
    
    // Then run the rest of the code and hope you didn't get a fatal error.
    $substr = mb_substr($your_64byte_nonce, $try, $try + \Sodium\CRYPTO_BOX_NONCEBYTES, '8bit');
    $decrypted = \Sodium\crypto_box_open($message, $substr, $keypair);
    if ($decrypted !== false) {
        echo $decrypted, "\n";
        echo "The magic slicing point is {$try}.\n";
    } else {
        exit(1);
    }
    

    如果它不起作用,可能还有其他问题。

    【讨论】:

    • 所以你的意思是我的 64 位随机数的一些 24 位子串会解密我的消息???
    • 它是真正的 64 位随机数还是 64 字节随机数?因为如果你以某种方式逃脱了 64 位随机数,我不知道该告诉你什么。我会说:试试看,如果没有,你已经丢失了数据。
    • 谢谢!你帮了大忙,今晚我会看看这个。而且你绝对是正确的哈哈我显然没有足够的红牛。
    猜你喜欢
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2020-03-20
    • 2017-10-23
    • 2018-03-22
    • 1970-01-01
    相关资源
    最近更新 更多