打包APK并对lua文件加密

打包apk并对lua文件加密,首先要有两个值
一个是签名,如果文件开头含有这个签名,那么表示这个文件是要加密的
一个是密码,也就是秘钥了,根据这个秘钥去生成加密后的文件

这两个值都是字符串,长度都是16个字符,将其加在如下这个函数中

bool AppDelegate::applicationDidFinishLaunching()
{
    // set default FPS
    Director * director = Director::getInstance();

    director->setAnimationInterval(1.0 / 50.0f);

    // register lua module
    auto engine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    lua_State* L = engine->getLuaStack()->getLuaState();
    register_all_packages( L );
    LuaStack* stack = engine->getLuaStack();

//这里添加------------------
    char * key = "你的加密密码";
    char * signature = "你的加密签名";
    stack->setXXTEAKeyAndSign(key, strlen(key), signature, strlen(signature));

    //register custom function
    //LuaStack* stack = engine->getLuaStack();
    //register_custom_function(stack->getLuaState());

    Node *node=Node::create();
    node->onEnter();
    Director::getInstance()->setNotificationNode(node);

    //testHttp();

#if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0)
    // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
    auto runtimeEngine = RuntimeEngine::getInstance();
    runtimeEngine->addRuntime(RuntimeLuaImpl::create(), kRuntimeEngineLua);
    runtimeEngine->start();
#else
    if (engine->executeScriptFile("src/main.lua"))
    {
        return false;
    }
#endif

    return true;
}

然后调用这个命令打包apk

cocos compile  -p android -m release -j 20  --lua-encrypt --lua-encrypt-key 你的加密密码 --lua-encrypt-sign 你的加密签名

你可能感兴趣的:(打包APK并对lua文件加密)