Skip to content

cipher:final() returns nil #185

Closed
Closed
@anbu1506

Description

@anbu1506
local cipher = require("resty.openssl.cipher")


local key = "12345678901234567890123456789012" -- 32 bytes
local iv = "1234567890123456" -- 16 bytes

local function init_encryption()
    local aes = cipher.new('aes256')
    aes:init(key, iv, {
        is_encrypt = true,
        no_padding = true
    })
    return aes
end

local function encrypt_chunk(aes, chunk)
    return aes:update(chunk)
end

local function complete_encryption(aes)
    return aes:final()
end

local function init_decryption()
    local aes = cipher.new('aes256')
    aes:init(key, iv, {
        is_encrypt = false,
        no_padding = true
    })
    return aes
end

local function decrypt_chunk(aes, chunk)
    return aes:update(chunk)
end

local function complete_decryption(aes)
    return aes:final()
end

return {
    init_encryption = init_encryption,
    encrypt_chunk = encrypt_chunk,
    complete_encryption = complete_encryption,
    init_decryption = init_decryption,
    decrypt_chunk = decrypt_chunk,
    complete_decryption = complete_decryption
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions