From 656fd4c0606046ae0ee27aaa58c3d235353d9840 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 3 Jul 2017 15:46:16 -0500 Subject: [PATCH] extract key generation --- Encrypter.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Encrypter.php b/Encrypter.php index 05c15e9..21f256d 100755 --- a/Encrypter.php +++ b/Encrypter.php @@ -59,6 +59,17 @@ public static function supported($key, $cipher) ($cipher === 'AES-256-CBC' && $length === 32); } + /** + * Create a new encryption key for the given cipher. + * + * @param string $cipher + * @return string + */ + public static function generateKey($cipher) + { + return random_bytes($cipher == 'AES-128-CBC' ? 16 : 32); + } + /** * Encrypt the given value. *