Esempio n. 1
0
cocos2d::LUA_STRING Crypto::cryptAES256Lua(bool isDecrypt,
                                             const char* input,
                                             int inputLength,
                                             const char* key,
                                             int keyLength)
{
    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
    stack->clean();
    if (getAES256KeyLength() == 0)
    {
        stack->pushNil();
        return 1;
    }
    
    int bufferSize = inputLength + getAES256KeyLength();
    void* buffer = malloc(bufferSize);
    int dataUsed = cryptAES256(isDecrypt, (unsigned char*)input, inputLength, (unsigned char*)buffer, bufferSize, (unsigned char*)key, keyLength);
    if (dataUsed > 0)
    {
        stack->pushString(static_cast<const char*>(buffer), dataUsed);
    }
    else
    {
        stack->pushNil();
    }
    free(buffer);
    return 1;
}
Esempio n. 2
0
LUA_STRING Crypto::encodingBase64Lua(bool isDecoding,
                                       const char* input,
                                       int inputLength)
{
    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
    stack->clean();

    int bufferSize = isDecoding ? Base64decode_len(input) : Base64encode_len(inputLength);
    char *buffer = bufferSize ? (char*)malloc(bufferSize) : NULL;
    int size = 0;

    if (buffer)
    {
        size = isDecoding ? Base64decode(buffer, input) : Base64encode(buffer, input, inputLength);
    }
    if (size)
    {
        stack->pushString(buffer, size);
    }
    else
    {
        stack->pushNil();
    }
    if (buffer)
    {
        free(buffer);
    }
    return 1;
}
int HelperFunc::getFileData(const char *pPathFile)
{
    unsigned long size;
    unsigned char* buf = HelperFunc::getFileData(pPathFile, "rb", &size);
    
    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
	stack->clean();
    if (buf) {
        stack->pushString((const char*)(buf), (int)size);
        delete buf;
    } else {
        stack->pushNil();
    }
    return 1;
}