It looks like you're new here. If you want to get involved, click one of these buttons!
require "lfs" local key = "GiderosGideros11" local iv = "GiderosRules2023" local paddingType = 1 local function cryptCopy(src, dst) local srcf = io.open(src, "rb") local dstf = io.open(dst, "wb") local size = 2^13 -- good buffer size (8K) while true do local block = srcf:read(size) if not block then break end block = Cryptography.aesEncrypt(block,key,iv,paddingType) dstf:write(block) end srcf:close() dstf:close() end local function decryptCopy(src, dst) local srcf = io.open(src, "rb") local dstf = io.open(dst, "wb") local size = 2^13 + 16 -- good buffer size (8K + 16 for padding) while true do local block = srcf:read(size) if not block then break end block = Cryptography.aesDecrypt(block,key,iv,paddingType) dstf:write(block) end srcf:close() dstf:close() end cryptCopy ("|D|myfile.sqlite", "C:/tmp/myfile.crypt") decryptCopy ("C:/tmp/myfile.crypt", "C:/tmp/myfile.sqlite") |
Likes: MoKaLux
Comments
You use a 8k buffer, which is 16 byte aligned so your code should work, but you use "r" for reading your files, even the crypted one, while you should really use "rb", to avoid line endings to be converted by the operating system.
Likes: MoKaLux, pie
Unfortunately I get the same exact error ( Invalid PKCS#7 padding value) using "rb" instead of "r" for reading files if I set paddingType as 0 or 1.
Likes: pie
Thank you a lot, we're lucky for having you here!
updating the code in the first post to use for anyone later
Likes: MoKaLux
Likes: pie