我需要在C#中使用Laravel的Crypt::Encrypt('secret')
時創建相同的結果。 我發現這個線程Rijndael 256 Encrypt/decrypt between c# and php? ,它似乎是我所需要的,但我有一些麻煩的第三個參數,初始化向量:(。將Laravel的AES 256加密器轉換爲C#
Laravel所有用戶必須輸入一個密鑰,在config文件夾,這是完全隨機的,32個字符長
的encyrption方法是這樣的:
public function encrypt($value)
{
$iv = mcrypt_create_iv($this->getIvSize(), $this->getRandomizer());
$value = base64_encode($this->padAndMcrypt($value, $iv));
// Once we have the encrypted value we will go ahead base64_encode the input
// vector and create the MAC for the encrypted value so we can verify its
// authenticity. Then, we'll JSON encode the data in a "payload" array.
$mac = $this->hash($iv = base64_encode($iv), $value);
return base64_encode(json_encode(compact('iv', 'value', 'mac')));
}
全Encryptor.php可以在這裏找到: http://pastebin.com/yfWLPxGn
任何想法,我將不得不輸入以獲得相同的結果? :)
函數「addPadding($ padding)」,應該是填充,對吧? – Jazerix
@Jazerix看起來像。 –