Skip to content

Commit

Permalink
Remove legacyDecrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Jan 27, 2017
1 parent 07ad835 commit 860d221
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/EasyRSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class EasyRSA implements EasyRSAInterface
{
const SEPARATOR = '$';
const VERSION_TAG = "EzR2";
const LEGACY_TAG = "EzR1";

/**
* KEM+DEM approach to RSA encryption.
Expand Down Expand Up @@ -83,9 +82,6 @@ public static function decrypt($ciphertext, PrivateKey $rsaPrivateKey)
if (\count($split) !== 4) {
throw new InvalidCiphertextException('Invalid ciphertext message');
}
if (\hash_equals($split[0], self::LEGACY_TAG)) {
return self::legacyDecrypt($ciphertext, $rsaPrivateKey);
}
if (!\hash_equals($split[0], self::VERSION_TAG)) {
throw new InvalidCiphertextException('Invalid version tag');
}
Expand Down Expand Up @@ -118,48 +114,6 @@ public static function decrypt($ciphertext, PrivateKey $rsaPrivateKey)
);
}

/**
* Encrypt a message with defuse/php-encryption, using an ephemeral key,
* then encrypt the key with RSA.
*
* @param string $ciphertext
* @param PrivateKey $rsaPrivateKey
*
* @return string
* @throws InvalidCiphertextException
* @throws InvalidChecksumException
*/
public static function legacyDecrypt($ciphertext, PrivateKey $rsaPrivateKey)
{
$split = explode(self::SEPARATOR, $ciphertext);
if (\count($split) !== 4) {
throw new InvalidCiphertextException('Invalid ciphertext message');
}
if (!\hash_equals($split[0], self::VERSION_TAG)) {
throw new InvalidCiphertextException('Invalid version tag');
}
$checksum = \substr(
\hash('sha256', implode('$', array_slice($split, 0, 3))),
0,
16
);
if (!\hash_equals($split[3], $checksum)) {
throw new InvalidChecksumException('Invalid checksum');
}

$key = Key::loadFromAsciiSafeString(
self::rsaDecrypt(
Base64::decode($split[1]),
$rsaPrivateKey
)
);
return Crypto::decrypt(
Base64::decode($split[2]),
$key,
true
);
}

/**
* Sign with RSASS-PSS + MGF1+SHA256
*
Expand Down

0 comments on commit 860d221

Please sign in to comment.