Skip to content

Commit febd9fc

Browse files
committed
WIP security encrypt
1 parent 02c2f08 commit febd9fc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/Libraries/Security.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8
5+
*
6+
* @category Library
7+
* @package Libraries
8+
* @author Made Mas Adi Winata <m45adiwinata@gmail.com>
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.5.0
11+
* @link https://github.com/spotlibs
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Spotlibs\PhpLib\Libraries;
17+
18+
/**
19+
* Security
20+
*
21+
* Security helper
22+
*
23+
* @category Library
24+
* @package Security
25+
* @author Made Mas Adi Winata <m45adiwinata@gmail.com>
26+
* @license https://mit-license.org/ MIT License
27+
* @link https://github.com/spotlibs
28+
*/
29+
class Security
30+
{
31+
public static function encrypt(string $plaintext): string
32+
{
33+
$plaintext = hex2bin($plaintext);
34+
if (!$plaintext) {
35+
throw new Exception("failed to convert plaintext into bin");
36+
}
37+
$ecrypted = openssl_encrypt($plaintext, "AES-128-CBC", "xxx", OPENSSL_ZERO_PADDING, "ivx");
38+
if (!$ecrypted) {
39+
throw new Exception("failed to encrypt string");
40+
}
41+
return $ecrypted;
42+
}
43+
}

0 commit comments

Comments
 (0)