ComputerCraft Forums

ComputerCraft => Programs => APIs and Utilities => Topic started by: ckupen on Dec 08, 2022, 04:44 AM

Title: AES encrypt library
Post by: ckupen on Dec 08, 2022, 04:44 AM
An API for AES encryption

Have stream encryption with Output feedback mode (OFB)

Link: <https://gist.github.com/zyxkad/a5e02d16d244b20b026ecfb06f662210>
Title: AES encrypt library
Post by: ckupen on Dec 08, 2022, 04:49 AM
Usage:

```lua
os.loadAPI('aes.lua')

key = string.rep('0', 16) -- A 16 bytes key, DO NOT use repeat bytes if you want safety
cipher = aes.Cipher:new(nil, key)
sec = cipher:encrypt("Hello world") -- data can be any length

data = cipher:decrypt(sec) -- Be careful, each decrypt must match a encrypt, you cannot jump off any data
print('data is:', data)

```
Title: AES encrypt library
Post by: sigma-octantis on Jul 21, 2023, 07:47 AM
Quote from: ckupen on Dec 08, 2022, 04:49 AMUsage:

```lua
os.loadAPI('aes.lua')

key = string.rep('0', 16) -- A 16 bytes key, DO NOT use repeat bytes if you want safety
cipher = aes.Cipher:new(nil, key)
sec = cipher:encrypt("Hello world") -- data can be any length

data = cipher:decrypt(sec) -- Be careful, each decrypt must match a encrypt, you cannot jump off any data
print('data is:', data)

```

Looks cool! I would change two things tho (They're very simple), return a table and use
require(), and maybe the gist link (If you click, appears broken at first).
(Basically os.loadAPI is deprecated) (https://tweaked.cc/module/os.html#v:loadAPI)

But with that tweaks, I'll probably use it on my server!

Nice work