Difference between revisions of "Cryptography"

From GiderosMobile
(Undo revision 13671 by MoKaLux (talk))
Tag: Undo
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Cryptography -->
 
<!-- GIDEROSOBJ:Cryptography -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2016.04<br/>
+
'''Available since:''' Gideros 2016.04<br/>
=== <translate>Description</translate> ===
+
 
<translate>Cryptographic primitives</translate>
+
=== Description ===
 +
Cryptographic primitives.
 +
 
 +
=== Example ===
 +
<syntaxhighlight 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")
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Cryptography.aesDecrypt|Cryptography.aesDecrypt]] ''<translate>Decrypt an AES string</translate>''<br/><!-- GIDEROSMTD:Cryptography.aesDecrypt(ciphertext,key,iv,paddingType) Decrypt an AES string -->
+
[[Cryptography.aesDecrypt]] ''decrypts an AES string''<br/><!--GIDEROSMTD:Cryptography.aesDecrypt(ciphertext,key,iv,paddingType) decrypts an AES string-->
[[Special:MyLanguage/Cryptography.aesEncrypt|Cryptography.aesEncrypt]] ''<translate>Encrypt a string with AES</translate>''<br/><!-- GIDEROSMTD:Cryptography.aesEncrypt(plaintext,key,iv,paddingType) Encrypt a string with AES -->
+
[[Cryptography.aesEncrypt]] ''encrypts a string with AES''<br/><!--GIDEROSMTD:Cryptography.aesEncrypt(plaintext,key,iv,paddingType) encrypts a string with AES-->
[[Special:MyLanguage/Cryptography.md5|Cryptography.md5]] ''<translate>Compute the MD5 hash of the input string</translate>''<br/><!-- GIDEROSMTD:Cryptography.md5(input) Compute the MD5 hash of the input string -->
+
[[Cryptography.b64]] ''Base64 encode some data''<br/><!--GIDEROSMTD:Cryptography.b64(data) Base64 encode some data-->
 +
[[Cryptography.md5]] ''computes the MD5 hash of the input string''<br/><!--GIDEROSMTD:Cryptography.md5(input) computes the MD5 hash of the input string-->
 +
[[Cryptography.pbkdf2]] ''Password-Based Key Derivation Function 2''<br/><!--GIDEROSMTD:Cryptography.pbkdf2(password,salt,iterations,outputLength) Password-Based Key Derivation Function 2-->
 +
[[Cryptography.sha1]] ''sha1 encode some data''<br/><!--GIDEROSMTD:Cryptography.sha1(data) sha1 encode some data-->
 +
[[Cryptography.unb64]] ''Base64 decode a string''<br/><!--GIDEROSMTD:Cryptography.unb64(string) Base64 decode a string-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
 
=== <translate>Constants</translate> ===
+
=== Events ===
 +
=== Constants ===
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 19:40, 15 December 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.pbkdf2 Password-Based Key Derivation Function 2
Cryptography.sha1 sha1 encode some data
Cryptography.unb64 Base64 decode a string

Events

Constants