Skip to content

Commit

Permalink
specify blank string IV for ECB
Browse files Browse the repository at this point in the history
  • Loading branch information
doersf committed Sep 10, 2022
1 parent 45d3b0b commit 5ec3a5e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,9 @@ public function encrypt($data, $key, $cipher_type = "AES-256-ECB", $iv = "", $au

$ciphertext = null;

if ($cipher_type == "AES-256-ECB") {
$response["aes_cipher_text"] = openssl_encrypt($data, strtolower($cipher_type), $key, OPENSSL_RAW_DATA, hex2bin($iv));
if ($cipher_type == "AES-256-ECB") {
// ECB takes no IV
$response["aes_cipher_text"] = openssl_encrypt($data, strtolower($cipher_type), $key, OPENSSL_RAW_DATA, hex2bin(""));
} elseif ($cipher_type == "AES-256-CBC") {
$response["aes_cipher_text"] = openssl_encrypt($data, strtolower($cipher_type), $key, OPENSSL_RAW_DATA, hex2bin($iv));
} elseif ($cipher_type == "AES-256-GCM") {
Expand Down Expand Up @@ -506,7 +507,8 @@ public function decrypt($b64ciphertext, $key, $cipher_type = "AES-256-ECB", $iv
$data_dec = null;

if ($cipher_type == "AES-256-ECB") {
$data_dec = openssl_decrypt($ciphertext_dec, strtolower($cipher_type), $key, OPENSSL_RAW_DATA, hex2bin($iv));
// ECB takes no IV
$data_dec = openssl_decrypt($ciphertext_dec, strtolower($cipher_type), $key, OPENSSL_RAW_DATA, hex2bin(""));
} elseif ($cipher_type == "AES-256-CBC") {
$data_dec = openssl_decrypt($ciphertext_dec, strtolower($cipher_type), $key, OPENSSL_RAW_DATA, hex2bin($iv));
} elseif ($cipher_type == "AES-256-GCM") {
Expand Down

0 comments on commit 5ec3a5e

Please sign in to comment.