Skip to content

Commit

Permalink
Disable padding
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <nguyennv1981@gmail.com>
  • Loading branch information
nguyennv committed Oct 22, 2024
1 parent c9843a4 commit ccdafa0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Packet/SecretKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ public function encrypt(
);
} else {
$cipher = $symmetric->cipherEngine(S2kUsage::Cfb->name);
$cipher->disablePadding();
$cipher->setIV($iv);
$cipher->setKey($kek);

Expand Down Expand Up @@ -505,6 +506,7 @@ public function decrypt(string $passphrase): self
);
} else {
$cipher = $this->symmetric->cipherEngine(S2kUsage::Cfb->name);
$cipher->disablePadding();
$cipher->setIV($this->iv);
$cipher->setKey($kek);
$decrypted = $cipher->decrypt($this->keyData);
Expand Down
2 changes: 2 additions & 0 deletions src/Packet/SymEncryptedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static function encryptPackets(
): self {
Helper::assertSymmetric($symmetric);
$cipher = $symmetric->cipherEngine(Config::CIPHER_MODE);
$cipher->disablePadding();
$cipher->setKey($key);
$cipher->setIV(str_repeat(Helper::ZERO_CHAR, $symmetric->blockSize()));
$prefix = $cipher->encrypt(Helper::generatePrefix($symmetric));
Expand Down Expand Up @@ -119,6 +120,7 @@ public function decrypt(
} else {
$blockSize = $symmetric->blockSize();
$cipher = $symmetric->cipherEngine(Config::CIPHER_MODE);
$cipher->disablePadding();
$cipher->setKey($key);
$cipher->setIV(substr($this->encrypted, 2, $blockSize));

Expand Down
2 changes: 2 additions & 0 deletions src/Packet/SymEncryptedIntegrityProtectedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static function encryptPackets(
$plainText = $toHash . hash(self::HASH_ALGO, $toHash, true);

$cipher = $symmetric->cipherEngine(Config::CIPHER_MODE);
$cipher->disablePadding();
$cipher->setKey($key);
$cipher->setIV(
str_repeat(Helper::ZERO_CHAR, $symmetric->blockSize())
Expand Down Expand Up @@ -265,6 +266,7 @@ public function decrypt(
$symmetric = $this->symmetric ?? $symmetric;
$size = $symmetric->blockSize();
$cipher = $symmetric->cipherEngine(Config::CIPHER_MODE);
$cipher->disablePadding();
$cipher->setKey($key);
$cipher->setIV(str_repeat(Helper::ZERO_CHAR, $size));

Expand Down
2 changes: 2 additions & 0 deletions src/Packet/SymmetricKeyEncryptedSessionKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public static function encryptSessionKey(
);
} else {
$cipher = $symmetric->cipherEngine(Config::CIPHER_MODE);
$cipher->disablePadding();
$cipher->setKey($key);
$cipher->setIV(
str_repeat(Helper::ZERO_CHAR, $symmetric->blockSize())
Expand Down Expand Up @@ -307,6 +308,7 @@ public function decrypt(string $password): self
$cipher = $this->symmetric->cipherEngine(
Config::CIPHER_MODE
);
$cipher->disablePadding();
$cipher->setKey($key);
$cipher->setIV(
str_repeat(
Expand Down

0 comments on commit ccdafa0

Please sign in to comment.