Skip to content

Commit

Permalink
determine encryption format from length
Browse files Browse the repository at this point in the history
  • Loading branch information
karakayasemi authored and IljaN committed May 28, 2021
1 parent c8d67f5 commit 16e8d34
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Crypto/CryptHSM.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CryptHSM extends Crypt {

const PATH_NEW_KEY = '/keys/new';
const PATH_DECRYPT = '/decrypt/'; // appended with keyid
const BINARY_ENCODED_KEY_LENGTH = 256;

/**
* @param ILogger $logger
Expand Down Expand Up @@ -166,9 +167,12 @@ public function multiKeyDecrypt($encKeyFile, $shareKey, $privateKey) { // done w
]);
$decryptedKey = $response->getBody();

// differentiate encryption type by looking key length
$binaryEncode = \strlen(\bin2hex($encKeyFile)) === self::BINARY_ENCODED_KEY_LENGTH;

// now decode the file.
// version and position are 0 because we always use fresh random data as passphrase
$decryptedContent = $this->symmetricDecryptFileContent($encKeyFile, $decryptedKey, self::DEFAULT_CIPHER, 0, 0, !$this->useLegacyEncoding());
$decryptedContent = $this->symmetricDecryptFileContent($encKeyFile, $decryptedKey, self::DEFAULT_CIPHER, 0, 0, $binaryEncode);

return $decryptedContent;
} catch (ServerException $e) {
Expand Down

0 comments on commit 16e8d34

Please sign in to comment.