-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK-2265 Retrieve Receipt Fix Decryption
- Loading branch information
1 parent
3806985
commit 404c706
Showing
8 changed files
with
101 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yoti\Identity\Util; | ||
|
||
use Yoti\Exception\EncryptedDataException; | ||
use Yoti\Protobuf\Compubapi\EncryptedData as EncryptedDataProto; | ||
|
||
class IdentityEncryptedData | ||
{ | ||
/** | ||
* @param string $data | ||
* @param string $wrappedKey | ||
* | ||
* @return string | ||
*/ | ||
public static function decrypt(string $data, string $unwrappedKey): string | ||
{ | ||
if ($data === false) { | ||
throw new EncryptedDataException('Could not decode data'); | ||
} | ||
|
||
$encryptedDataProto = new EncryptedDataProto(); | ||
$encryptedDataProto->mergeFromString($data); | ||
|
||
$decrypted = openssl_decrypt( | ||
$encryptedDataProto->getCipherText(), | ||
'aes-256-cbc', | ||
$unwrappedKey, | ||
OPENSSL_RAW_DATA, | ||
$encryptedDataProto->getIv() | ||
); | ||
|
||
if ($decrypted !== false) { | ||
return $decrypted; | ||
} | ||
|
||
throw new EncryptedDataException('Could not decrypt data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters