first commit
This commit is contained in:
34
lib/Security/Aes/AesEncryptor.php
Normal file
34
lib/Security/Aes/AesEncryptor.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Yeepay\Yop\Sdk\Security\Aes;
|
||||
|
||||
class AesEncryptor
|
||||
{
|
||||
|
||||
private static $AES_METHOD = 'aes-256-cbc';
|
||||
|
||||
private static $AES_IV;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
$str = '';
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$str .= chr(0);
|
||||
}
|
||||
self::$AES_IV = $str;
|
||||
}
|
||||
|
||||
public static function encryptAndEncodeBase64($data, $key)
|
||||
{
|
||||
return base64_encode(openssl_encrypt($data, self::$AES_METHOD, $key, OPENSSL_RAW_DATA, self::$AES_IV));
|
||||
}
|
||||
|
||||
public static function decodeBase64AndDecrypt($base64EncodedData, $key)
|
||||
{
|
||||
return openssl_decrypt(base64_decode($base64EncodedData), self::$AES_METHOD, $key, OPENSSL_RAW_DATA,
|
||||
self::$AES_IV);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AesEncryptor::init();
|
||||
12
lib/Security/DigestAlg.php
Normal file
12
lib/Security/DigestAlg.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Yeepay\Yop\Sdk\Security;
|
||||
|
||||
abstract class DigestAlg
|
||||
{
|
||||
|
||||
const SHA256 = 'SHA256';
|
||||
|
||||
const SHA512 = 'SHA512';
|
||||
|
||||
}
|
||||
18
lib/Security/Encodes.php
Normal file
18
lib/Security/Encodes.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Yeepay\Yop\Sdk\Security;
|
||||
|
||||
class Encodes
|
||||
{
|
||||
|
||||
public static function base64url_encode($data)
|
||||
{
|
||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||
}
|
||||
|
||||
public static function base64url_decode($data)
|
||||
{
|
||||
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user