基础 - Xlog 加密使用指引 - 《Mars 开发文档》 - 书栈网 · BookStack
一、准备环境--Python2
准备Python2的环境,下面的一切操作都要在该环境下进行。
安装pyelliptic1.5.10
https://github.com/mfranciszkiewicz/pyelliptic/archive/1.5.10.tar.gz#egg=pyelliptic
文档中写的是1.5.7,在踩坑过程中发现在新版本的macos下已不可用,已经有人提交了Issues,并给出了解决方案Exception: Couldn't load OpenSSL lib , 升级到MACOS 11.5.1后出现 · Issue #969 · Tencent/mars (github.com)
将pyelliptic1.5.10进行解压后,修改pyelliptic-1.5.10/pyelliptic.py文件中的内容
def find_crypto_lib():
if sys.platform != 'win32':
# 注释掉下面路径,写绝对路径
# return ctypes.util.find_library('crypto')
return '/usr/lib/libcrypto.dylib'
在Python2的环境下进行安装,到pyelliptic-1.5.10目录 执行
python setup.py install
二、生成公私钥
到Mars目录下mars-master/mars/log/crypt/gen_key.py
执行gen_key.py文件
python gen_key.py
save private key:#私钥
xxxxxxxxxxxx
appender_open's parameter:#公钥
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
将私钥和公钥配置到decode_mars_crypt_log_file.py中
PRIV_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
PUB_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
三、修改android中Xlog的初始化代码
val SDCARD: String = Environment.getExternalStorageDirectory().absolutePath
val logPath: String = SDCARD + "/marssample/log"
// this is necessary, or may crash for SIGBUS
val cachePath: String = Ktx.app.filesDir.absolutePath + "/xlog"
val xlog = Xlog()
Log.setLogImp(xlog)
Log.setConsoleLogOpen(true)
Xlog.open(true,Xlog.LEVEL_DEBUG, Xlog.AppednerModeAsync, cachePath, logPath, "your_tag", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
四、解密日志文件
使用decode_mars_crypt_log_file.py进行解密
python /Users/hanxueqiang/yuanmanyuan/mars-master/mars/log/crypt/decode_mars_crypt_log_file.py /Users/hanxueqiang/Downloads/dbx_local_20211118.xlog