forked from apoloz/alfa-bank-sdk
refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
36
tests/Feature/Utils/CryptoTest.php
Normal file
36
tests/Feature/Utils/CryptoTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Apoloz\AlfaBank\Utils\CardEncryptor;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
|
||||
test('can encrypt card pan', function () {
|
||||
// Generate a temporary RSA key for testing
|
||||
$res = openssl_pkey_new([
|
||||
"private_key_bits" => 2048,
|
||||
"private_key_type" => OPENSSL_KEYTYPE_RSA,
|
||||
]);
|
||||
openssl_pkey_export($res, $privateKey);
|
||||
$details = openssl_pkey_get_details($res);
|
||||
$publicKey = $details['key'];
|
||||
|
||||
$pan = '4779642610000010';
|
||||
$encrypted = CardEncryptor::encrypt($pan, $publicKey);
|
||||
|
||||
expect($encrypted)->toBeString()
|
||||
->and(base64_decode($encrypted))->not->toBeFalse();
|
||||
});
|
||||
|
||||
test('can canonicalize json', function () {
|
||||
$data = [
|
||||
'z' => 1,
|
||||
'a' => [
|
||||
'c' => 3,
|
||||
'b' => 2
|
||||
]
|
||||
];
|
||||
|
||||
$canonical = CmsSigner::canonicalize($data);
|
||||
|
||||
// Keys should be sorted: a (then b, c), z
|
||||
expect($canonical)->toBe('{"a":{"b":2,"c":3},"z":1}');
|
||||
});
|
||||
Reference in New Issue
Block a user