public function encryptBinary(string $value, string $key): string
    {
        $key = $this->hashKey($key);
        $opts = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING;
        $iv = random_bytes($this->ivLength);
        $encrypted = openssl_encrypt($value, $this->cipher, $key, $opts, $iv);
        if ($encrypted === false) {
            throw new \Exception("encryption failed; ".openssl_error_string());
        }
        return $iv.$encrypted;
    }
public function encryptBinary(string $value, string $key): string
    {
        $key = $this->hashKey($key);
        $opts = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING;
        $iv = random_bytes($this->ivLength);
        $encrypted = openssl_encrypt($value, $this->cipher, $key, $opts, $iv);
        if ($encrypted === false) {
            throw new \Exception("encryption failed; ".openssl_error_string());
        }
        return $iv.$encrypted;
    }
public function encryptBinary ( string $ value , string $ key ) : string { $ key = $ this -> hashKey ( $ key ) ; $ opts = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING ; $ iv = random_bytes ( $ this -> ivLength ) ; $ encrypted = openssl_encrypt ( $ value , $ this -> cipher , $ key , $ opts , $ iv ) ; if ( $ encrypted === false ) { throw new \ Exception ( "encryption failed; " . openssl_error_string ( ) ) ; } return $ iv . $ encrypted ; }
Encrypt a value

@param string $value The value to encrypt
@param string $key The key
@return string The encrypted value
@throws \Exception If the encryption fails
Encrypt a value