Answer the question
In order to leave comments, you need to log in
How to encode a variable, send it to the database. Then get and decode back?
Hello, I need help with php:
I am writing api. It comes with 3 variables - $a, $code, $b.
You need to encode code. I do it through OpenSSL:
define('ENCRYPTION_KEY', 'ТУТ КОД ШИФРОВАНИЯ')
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($code, $cipher, ENCRYPTION_KEY, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, ENCRYPTION_KEY, $as_binary=true);
$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw );
Answer the question
In order to leave comments, you need to log in
As if straight from the documentation, the second example: https://www.php.net/manual/en/function.openssl-enc...
$c = base64_decode($ciphertext);
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = substr($c, 0, $ivlen);
$hmac = substr($c, $ivlen, $sha2len=32);
$ciphertext_raw = substr($c, $ivlen+$sha2len);
$original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv);
$calcmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary=true);
if (hash_equals($hmac, $calcmac))//PHP 5.6+ timing attack safe comparison
{
echo $original_plaintext."\n";
}
solved the question itself)
you need to add the rule
route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.114 in router 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question