Jump to content




AES Encryption


68 replies to this topic

#1 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 29 May 2014 - 10:33 AM

Inspired by Sha-256 in Lua I chose to implement AES. If you are happy to wait a second or two for almost guaranteed security then this is the program for you!

Usage:
os.loadAPI("aeslua")
local iv = {}
for i = 1, 16 do iv[i] = math.random(1, 255) end
aeslua.encrypt("MyKey", "My Message", aealua.AES128, aeslua.CBCMODE, iv)
aeslua.decrypt("MyKey", "My Encrypted Message", aealua.AES128, aeslua.CBCMODE, iv)

There are some more examples at the tests directory.

Stuff I've based this on: AES for Lua

Getting It:
Its on Github if you want to read all the code. You can fetch the raw file through wget or the HTTP API.

You can also use pastebin to download it: wget https://git.io/aeslua aeslua or pastebin run LYAxmSby get 86925e07cbabd70773e53d781bd8b2fe/aeslua.min.lua aeslua

Edit:
Unknown to me this has already been implemented before, by KleinRefrigerator and KillaVanilla. This implementation gives you access to 128, 192 and 265 bit versions and ECB, CBC, CFB, OFB and CTR modes and so is more flexible.

Edited by SquidDev, 15 March 2018 - 10:41 AM.


#2 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 29 May 2014 - 10:51 AM

Were you aware of the bit API? It's a CC builtin.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 29 May 2014 - 11:06 AM

View Postskwerlman, on 29 May 2014 - 10:51 AM, said:

Were you aware of the bit API? It's a CC builtin.
The CC bit API doesn't have to_bits anymore, and the shift operations don't work the same as in that external API.

#4 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 29 May 2014 - 11:21 AM

View Posttheoriginalbit, on 29 May 2014 - 11:06 AM, said:

View Postskwerlman, on 29 May 2014 - 10:51 AM, said:

Were you aware of the bit API? It's a CC builtin.
The CC bit API doesn't have to_bits anymore, and the shift operations don't work the same as in that external API.

Quite. The CC Bit API doesn't work with numbers greater than 232-1. I had the same issue as GravityScore did and so had to use an external Bit API.

#5 Retriever

  • Members
  • 7 posts
  • LocationUK

Posted 31 May 2014 - 04:44 PM

Nice and simple API, been trying to get RSA working in CC but i don't understand the math enough to get it fully working and the encryption times were hugely impractical so this will do very nicely :)

#6 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 31 May 2014 - 04:48 PM

View PostRetriever, on 31 May 2014 - 04:44 PM, said:

Nice and simple API, been trying to get RSA working in CC but i don't understand the math enough to get it fully working and the encryption times were hugely impractical so this will do very nicely :)

Thanks, nice to know that its helping someone. :)

#7 Magik6k

  • Members
  • 29 posts

Posted 02 June 2014 - 02:41 PM

Awesome API! I probably see one pretty interesting use to this :D .

#8 Anavrins

  • Members
  • 775 posts

Posted 03 June 2014 - 01:26 AM

View PostSquidDev, on 29 May 2014 - 10:33 AM, said:

Unknown to me this has already been implemented before, by KleinRefrigerator and KillaVanilla. This implimentation gives you access to 128, 192 and 265 bit versions and ECB, CBC, CFB, OFB modes and so is more flexible.
What about CTR mode?
Would be nice to have it too :P
Killa's implementation of CTR is broken...

#9 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 03 June 2014 - 07:24 AM

View PostAnavrins, on 03 June 2014 - 01:26 AM, said:

View PostSquidDev, on 29 May 2014 - 10:33 AM, said:

Unknown to me this has already been implemented before, by KleinRefrigerator and KillaVanilla. This implimentation gives you access to 128, 192 and 265 bit versions and ECB, CBC, CFB, OFB modes and so is more flexible.
What about CTR mode?
Would be nice to have it too :P
Killa's implementation of CTR is broken...

I'll have a look in to it, looks quite interesting.

#10 GreenByteSoftware

  • Members
  • 135 posts
  • LocationKaunas, Lithuania

Posted 05 June 2014 - 10:42 AM

Could I use this implementation in my PockyOS (I will give credit)

#11 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 05 June 2014 - 10:46 AM

View Postthediamondgames, on 05 June 2014 - 10:42 AM, said:

Could I use this implementation in my PockyOS (I will give credit)

Sure, I'm not fussed what happens with it. Thanks for asking though.

#12 GreenByteSoftware

  • Members
  • 135 posts
  • LocationKaunas, Lithuania

Posted 05 June 2014 - 11:49 AM

View PostSquidDev, on 05 June 2014 - 10:46 AM, said:

View Postthediamondgames, on 05 June 2014 - 10:42 AM, said:

Could I use this implementation in my PockyOS (I will give credit)

Sure, I'm not fussed what happens with it. Thanks for asking though.
But just noticed problem: When I encrypt my password with the same key as password is, write those symbols to file. While trying to decrypt password by accessing the same symbols from the same file with the same key it doesn't decrypt, tried doing with lua shell and while setting for example x as decrypted text from the file and when I type print(x) it leaves an empty line + everytime I encrypt with the same text I noticed that the symbols are always different.

#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 June 2014 - 12:02 PM

View Postthediamondgames, on 05 June 2014 - 11:49 AM, said:

When I encrypt my password -snip- While trying to decrypt password -snip-
Don't use encryption for passwords, use hashing. I've written up reasons for this a lot, so I'll just link any I can quickly find instead of typing it out again.
An explanation.
Links to SHA256 algorithm implementations.
User Accounts w/ Hashing Code Examples.

Edited by theoriginalbit, 05 June 2014 - 12:02 PM.


#14 GreenByteSoftware

  • Members
  • 135 posts
  • LocationKaunas, Lithuania

Posted 05 June 2014 - 12:05 PM

View Posttheoriginalbit, on 05 June 2014 - 12:02 PM, said:

View Postthediamondgames, on 05 June 2014 - 11:49 AM, said:

When I encrypt my password -snip- While trying to decrypt password -snip-
Don't use encryption for passwords, use hashing. I've written up reasons for this a lot, so I'll just link any I can quickly find instead of typing it out again.
An explanation.
Links to SHA256 algorithm implementations.
User Accounts w/ Hashing Code Examples.
Well yes, after this problem I quickly fitted in gravityscore's sha256 implementation, it works the way better without bugs

#15 DiamondTNT

  • Members
  • 8 posts
  • LocationGallifrey

Posted 06 June 2014 - 08:36 PM

What mode of AES does this implementation use?

#16 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 07 June 2014 - 08:12 AM

This implimentation gives you access to 128, 192 and 265 bit versions and ECB, CBC, CFB, OFB modes and so is more flexible.

Don't use Electronic Cookbook mode (ECB) as it is insecure when encrypting large amounts of data. For more information use see Wikipedia and StackOverflow.

#17 lebalusch

  • Members
  • 49 posts

Posted 29 June 2014 - 05:11 PM

Hi not really following where I am going wrong. So i download your file and store it as AES.

Spoiler

How do I decrypt the text at a later date? I know the key "TheKey"

#18 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 29 June 2014 - 08:04 PM

View Postlebalusch, on 29 June 2014 - 05:11 PM, said:

Hi not really following where I am going wrong. So i download your file and store it as AES.

Spoiler

How do I decrypt the text at a later date? I know the key "TheKey"

os.loadAPI("AES")
local enc = AES.encrypt("MyKey", "My Message")
print(AES.decrypt("MyKey", enc))

This is the basic way of doing it. If you want to save/load the encrypted data to/from a file you will have to use binary mode as normal files don't support characters > 127.

#19 lebalusch

  • Members
  • 49 posts

Posted 29 June 2014 - 08:12 PM

View PostSquidDev, on 29 June 2014 - 08:04 PM, said:

View Postlebalusch, on 29 June 2014 - 05:11 PM, said:

Hi not really following where I am going wrong. So i download your file and store it as AES.

Spoiler

How do I decrypt the text at a later date? I know the key "TheKey"

os.loadAPI("AES")
local enc = AES.encrypt("MyKey", "My Message")
print(AES.decrypt("MyKey", enc))

This is the basic way of doing it. If you want to save/load the encrypted data to/from a file you will have to use binary mode as normal files don't support characters > 127.
Is this not effectively what I have done here?

os.loadAPI("AES")
key = "TheKey"
AEScode = "??~ ??? ;[email protected]???;???2?M??????9??"
A = AES.decrypt(key, AEScode)
print("and back: ", A)


#20 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 30 June 2014 - 12:52 AM

if you've manually typed that string based off what the terminal has shown, then you've typed it wrong, any non-displaying character in ComputerCraft is drawn with a '?'





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users