public function testSelfEncryptedVersion2VectorIsVersion2()
 {
     $encryptor = new Encryptor();
     $encrypted = $encryptor->encrypt(self::SAMPLE_PLAINTEXT, self::SAMPLE_PASSWORD, 2);
     $actualVersion = ord(substr(base64_decode($encrypted), 0, 1));
     $this->assertEquals(2, $actualVersion);
 }
Exemplo n.º 2
0
 public function onReceive(swoole_client $cli, $data)
 {
     Trace::debug("*********cli {$this->fd} receive  lenght:" . strlen($data) . ".");
     false !== $this->serv->connection_info($this->fd) && $this->serv->send($this->fd, $this->cryptor->encrypt($data));
     $this->lock = false;
     $this->send();
 }
Exemplo n.º 3
0
 public function testPasswordVectors()
 {
     $vectors = $this->_getVectors('password');
     foreach ($vectors as $vector) {
         $encryptor = new Encryptor();
         $encryptedB64 = $encryptor->encryptWithArbitrarySalts($this->_prettyHexToBin($vector['plaintext_hex']), $vector['password'], $this->_prettyHexToBin($vector['enc_salt_hex']), $this->_prettyHexToBin($vector['hmac_salt_hex']), $this->_prettyHexToBin($vector['iv_hex']), $vector['version']);
         $this->assertEquals($vector['ciphertext_hex'], $this->_binToPrettyHex(base64_decode($encryptedB64)));
     }
 }
Exemplo n.º 4
0
    /**
     * Get Anubis object
     * @return Anubis
     */
    public static function getAnubis()
    {
        if (!self::$anubis) {
            $cypher = new Anubis();
            $cypher->setKey(self::$key, true);
            self::$anubis = $cypher;
        }

        return self::$anubis;
    }
Exemplo n.º 5
0
 private static function insertUserIntoDB($username, $password, $email)
 {
     //TODO make this use DBConnection::executeSQLCommand
     $connection = DBConnection::getConnection();
     $encryptedPassword = Encryptor::encrypt($password);
     $statement = $connection->prepare('INSERT INTO Users (username, email, password) VALUES (:username, :email, :password)');
     $statement->bindParam(':username', $username);
     $statement->bindParam(':email', $email);
     $statement->bindParam(':password', $encryptedPassword);
     $successful = $statement->execute();
     return $successful;
 }
Exemplo n.º 6
0
 /**
  * 调用纳客接口.
  *
  * @param string $_method 接口方法名
  * @param array  $data    发送的数据
  */
 public function callnake($_method, array $data = array())
 {
     //实际请求地址
     $url = trim($this->interfaceUrl, '/ \\/') . '/Interface/GeneralInterfaceHandler.ashx';
     //请求方法名加入到参数中
     $data['do'] = $_method;
     //如果是商盟旗舰版,则参数中加入店铺ID
     if ($this->luckVersion === self::LUCK_VERSION_ULTIMATE) {
         $data['ShopID'] = $this->shopId;
     }
     //数据
     foreach ($data as $key => $value) {
         $data[$key] = $this->encryptor->encrypt($value);
     }
     //企业代码不加密
     $data['CompCode'] = $this->companyCode;
     $this->result = $this->http->post($url, $data);
     return $this->result;
 }
Exemplo n.º 7
0
 public function __construct($key, $method)
 {
     $this->_key = $key;
     $this->_method = $method;
     if ($this->_method == 'table') {
         $this->_method = null;
     }
     if ($this->_method) {
         $iv_size = openssl_cipher_iv_length($this->_method);
         $iv = openssl_random_pseudo_bytes($iv_size);
         $this->_cipher = $this->getcipher($this->_key, $this->_method, 1, $iv);
     } else {
         if (!self::$_encryptTable) {
             $_ref = self::getTable($this->_key);
             self::$_encryptTable = $_ref[0];
             self::$_decryptTable = $_ref[1];
         }
     }
 }
Exemplo n.º 8
0
define('STAGE_CONNECTING', 4);
define('STAGE_STREAM', 5);
define('STAGE_DESTROYED', -1);
// 命令
define('CMD_CONNECT', 1);
define('CMD_BIND', 2);
define('CMD_UDP_ASSOCIATE', 3);
// 初始化worker,监听$LOCAL_PORT端口
$worker = new Worker('tcp://0.0.0.0:' . $LOCAL_PORT);
// 进程数量
$worker->count = $PROCESS_COUNT;
// 名称
$worker->name = 'shadowsocks-local';
// 如果加密算法为table,初始化table
if ($METHOD == 'table') {
    Encryptor::initTable($PASSWORD);
}
// 当客户端连上来时
$worker->onConnect = function ($connection) use($METHOD, $PASSWORD) {
    // 设置当前连接的状态为STAGE_INIT,初始状态
    $connection->stage = STAGE_INIT;
    // 初始化加密类
    $connection->encryptor = new Encryptor($PASSWORD, $METHOD);
};
// 当客户端发来消息时
$worker->onMessage = function ($connection, $buffer) use($LOCAL_PORT, $SERVER, $PORT) {
    // 判断当前连接的状态
    switch ($connection->stage) {
        case STAGE_INIT:
            //与客户端建立SOCKS5连接
            //参见: https://www.ietf.org/rfc/rfc1928.txt
Exemplo n.º 9
0
 /**
  * @param mixed $key
  *
  * @dataProvider encryptWithEmptyKeyDataProvider
  */
 public function testEncryptWithEmptyKey($key)
 {
     $model = new Encryptor($this->_randomGenerator, $this->_cryptFactory, $key);
     $value = 'arbitrary_string';
     $this->assertEquals($value, $model->encrypt($value));
 }
Exemplo n.º 10
0
 private function _generateEncryptedStringWithUnsupportedSchemaNumber($fakeSchemaNumber)
 {
     $encryptor = new Encryptor();
     $plaintext = 'The price of ice is nice for mice';
     $encrypted = $encryptor->encrypt($plaintext, self::SAMPLE_PASSWORD);
     $encryptedBinary = base64_decode($encrypted);
     $encryptedBinary = chr($fakeSchemaNumber) . substr($encryptedBinary, 1, strlen($encryptedBinary - 1));
     return base64_encode($encryptedBinary);
 }
Exemplo n.º 11
0
 public function passwordMatches($password)
 {
     return $this->encryptedPassword === Encryptor::encrypt($password);
 }
Exemplo n.º 12
0
 /**
  *
  */
 protected function afterFind () {
     $this->Customer_ID= Encryptor::decrypt($this->Customer_ID);
     return parent::afterFind();
 }