Difference between revisions of "Cryptography"

From GiderosMobile
(removed language stuff)
Line 6: Line 6:
 
=== Description ===
 
=== Description ===
 
Cryptographic primitives.
 
Cryptographic primitives.
 +
 +
=== Example ===
 +
<source lang="lua">
 +
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")
 +
</source>
  
 
{|-
 
{|-

Revision as of 18:54, 28 February 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2016.04

Description

Cryptographic primitives.

Example

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")

Methods

Cryptography.aesDecrypt decrypts an AES string
Cryptography.aesEncrypt encrypts a string with AES
Cryptography.b64 Base64 encode some data
Cryptography.md5 computes the MD5 hash of the input string
Cryptography.unb64 Base64 decode a string

Events

Constants