【问题标题】:Get iv string when performing Crypt::encrypt in Laravel在 Laravel 中执行 Crypt::encrypt 时获取 iv 字符串
【发布时间】:2016-09-27 19:32:39
【问题描述】:

我正在尝试使用 Laravel 加密的用户名和密码进行跨域 ajax 调用,但我无法找到在 Crypt::encrypt 操作期间生成的 IV 字符串的方法。找到它的最佳方法是什么?

更新(添加代码):

$encUsername = Crypt::encrypt($username);
$encPassword = Crypt::encrypt($password);

JavaScript::put([
  'username' => $encUsername,
  'password' => $encPassword
]);

【问题讨论】:

  • 有代码吗?将其添加到问题中。
  • 您需要 IV 做什么?
  • @ScottArciszewski 我需要它用于另一端的 php mcrypt_decrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] ) 函数(在 laravel 应用程序之外)。

标签: php laravel encryption


【解决方案1】:

查看source codeencrypt()的结果是base64编码的JSON数据:

    $iv = random_bytes($this->getIvSize());
    $value = \openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);

    // ...
    $mac = $this->hash($iv = base64_encode($iv), $value);
    $json = json_encode(compact('iv', 'value', 'mac'));

    // ...
    return base64_encode($json);

您需要base64_decodejson_decode 的值,然后使用iv 键。

【讨论】:

  • 非常感谢,我想我正确地实现了它:$json = base64_decode($encUsername); $iv = json_decode($json); $iv = $iv->iv;
猜你喜欢
  • 1970-01-01
  • 2015-11-08
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多