douyuefei3546 2018-04-21 00:54
浏览 453
已采纳

jQuery加密数据

Actually my problem is ridiculous. I provide security by adding header. When I add the encrypted data, the browser gives an error.

Code source output :

headers: {
    "Authorization": "���6���/��O��u�f�߁v2��",
},

Console Output

Browser detects:

headers: {
    "Authorization": "���6���/��O��
u�f�߁v2��",
},

PHP Code :

 headers: {
     "Authorization": "<?php echo $_SESSION['sID']; ?>",
 },

My Session Class :

class Session {

    public function __construct() {
        if(session_status() == PHP_SESSION_NONE) {
            session_start();
        }
        self::Encrypt('sID', session_id());
    }

    public static function Encrypt($Name, $Value) {
        if(!is_null($Value)) {
            $_SESSION[$Name] = openssl_encrypt($Value, Config::Get('Encrypt/Type'), Config::Get('Encrypt/Password'), OPENSSL_RAW_DATA, Config::Get('Encrypt/Session'));
            return $_SESSION[$Encrypt];
        }
        return false;
    }
 }

What is the problem? Does anyone have an idea ? Best regards !

Also : str_replace and trim tried its functions.

  • 写回答

1条回答 默认 最新

  • dongyi7966 2018-04-21 01:32
    关注

    The return value of openssl_encrypt() with the OPENSSL_RAW_DATA flag set will generally not be a printable string. It will usually contain invalid UTF-8 characters, and may sometimes include characters which will interfere with Javascript code parsing, like quotation marks.

    Don't use the OPENSSL_RAW_DATA flag here. Without this flag set, the function will return Base64-encoded output, which is more appropriate for your needs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题