-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sms verification code encryption for verify endpoint complete
- Loading branch information
1 parent
8486c3f
commit 56b85d5
Showing
3 changed files
with
53 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model; | ||
|
||
class C2CSubMerchantApiCredentials { | ||
private string $salt; | ||
private string $secretKey; | ||
|
||
public function getSalt(): ?string { | ||
return $this->salt ?? null; | ||
} | ||
|
||
public function setSalt(string $salt): void { | ||
$this->salt = $salt; | ||
} | ||
|
||
public function getSecretKey(): ?string { | ||
return $this->secretKey ?? null; | ||
} | ||
|
||
public function setSecretKey(string $secretKey): void { | ||
$this->secretKey = $secretKey; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Iyzipay/Model/C2CSubMerchantSmsVerificationCodeEncrypter.php
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,19 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model; | ||
|
||
class C2CSubMerchantSmsVerificationCodeEncrypter { | ||
public static function encrypt(C2CSubMerchantApiCredentials $credentials, string $smsVerificationCode): string { | ||
$salt = $credentials->getSalt(); | ||
$secretKey = $credentials->getSecretKey(); | ||
|
||
if (is_null($salt) || is_null($secretKey)) { | ||
throw new \InvalidArgumentException('Please setup credentials!'); | ||
} | ||
|
||
$data = hash_pbkdf2('sha256', $smsVerificationCode, $salt, 65536, 0, true); | ||
$initVector = openssl_random_pseudo_bytes(16, $crypto_strong); | ||
$ciphertext = openssl_encrypt($data, 'aes-256-cbc-hmac-sha256', $secretKey, OPENSSL_RAW_DATA, $initVector); | ||
return base64_encode($ciphertext); | ||
} | ||
} |