12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2018/7/5
- * Time: 下午4:41
- */
- namespace room;
- class author
- {
- static public function sign_web($roomid,$userid)
- {
- $data = ['room' => $roomid,'user' => $userid,'acctype' => proto_type::acc_web_type];
- $plaintext = json_encode($data);
- $cipher="AES-128-CBC";
- $ivlen = openssl_cipher_iv_length($cipher);
- $iv = self::zero_iv($ivlen);
- return openssl_encrypt($plaintext, $cipher, self::passwd(), 0, $iv);
- }
- static public function sign_native($userid)
- {
- $data = ['user' => $userid,'room' => 0,'acctype' => proto_type::acc_native_type];
- $plaintext = json_encode($data);
- $cipher="AES-128-CBC";
- $ivlen = openssl_cipher_iv_length($cipher);
- $iv = self::zero_iv($ivlen);
- return openssl_encrypt($plaintext, $cipher, self::passwd(), 0, $iv);
- }
- static public function sign_all($userid)
- {
- $data = ['user' => $userid,'room' => 0,'acctype' => proto_type::acc_all_type];
- $plaintext = json_encode($data);
- $cipher="AES-128-CBC";
- $ivlen = openssl_cipher_iv_length($cipher);
- $iv = self::zero_iv($ivlen);
- return openssl_encrypt($plaintext, $cipher, self::passwd(), 0, $iv);
- }
- public function verify()
- {
- }
- static private function zero_iv($ivlen)
- {
- $iv = '';
- for ($i = 0; $i < $ivlen; ++$i) {
- $iv .= chr(0);
- }
- return $iv;
- }
- static private function passwd()
- {
- global $config;
- $pass = $config['room_password'];
- return $pass;
- }
- }
|