Jump to content




AES Encryption


  • You cannot reply to this topic
68 replies to this topic

#41 Rougeminner

  • Members
  • 151 posts

Posted 30 November 2014 - 01:16 AM

View PostKingofGamesYami, on 29 November 2014 - 07:23 PM, said:

View PostRougeminner, on 29 November 2014 - 06:57 PM, said:

i get a java election thrown error. is it because i am encoding a string
This is meant to encode strings, so no

View PostRougeminner, on 29 November 2014 - 06:57 PM, said:

if i provide the code can you tell me what i am doing wrong after i implemented base64
Yes

View PostRougeminner, on 29 November 2014 - 06:57 PM, said:

right now i have transmit code input2 = Base64.encode(input2) input2 = AES.encrypt("XXXX",input2) redness.broadcast(input2,channel) and receive code is if event == "rednet_message" then arg2 = AES.decrypt(arg2) print(arg1,',',arg2)
Well, considering you never decrypted from base64, that would never work. Also, since you encrypted in base64 before encrypting with AES, it won't protect against event corruption.
 input2 = base64.encode( AES.encrypt( "XXX", input2 ) ) rednet.broadcast( input2 ) 
 if event == "rednet_message" then arg2 = AES.decrypt( base64.decrypte( arg2 ) ) print(arg1,',',arg2) 

what do you mean event corruption. i still get a java exception thrown error. Almost forgot heres my code


os.loadAPI("apps/aes/framework/AES")
os.loadAPI('Base64')
print("please enter encryption key/salt")
key = read("*")
print("please enter protocol")
input3 = read()
rednet.host("rougeminner",input3)
term.setCursorPos(1,1)
term.clear()
string1 = "Rougeminner Has left this chat "--id was ",os.getComputerID()
rednet.open("left")
rednet.broadcast("Rougeminner has joined the Chat")
running = true
while running do
event,arg1,arg2,arg3 = os.pullEventRaw()
if event == "mouse_click" then
if arg1 == 1 and arg2 == 1 and arg3 == 1 then
running = false
rednet.broadcast(string1)--,os.getComputerID())
else
end
elseif event == "key" then
--print(arg1)
if arg1 == 29 then
rednet.broadcast(string1)
term.setCursorPos(1,1)
term.clear()
running = false
end
elseif event == "rednet_message" then
arg2 = Base64.decode(AES.decrypt(key,arg2))
print('ID: ',arg1," message ",arg2)
elseif arg2 == nil then
--print("please enter ID")input1 = read()
--term.setCursorPos(1,17)
--term.setCursorPos(1,10)
print("Enter Message")input2 = read()
--print("please Enter Protocol") input3 = read()
--h = tonumber(input3)
--rednet.broadcast(input2,"TCP1")--input3)
--if input2:sub(1,1) == "/" then
--print("Commands are: /List , /leave , /clear")
if input2 == "/clear" then
term.clear()
term.setCursorPos(1,1)
elseif input2 == "/help" then
print("commands are /help , /clear , and you can press left control to leave along with clicking a cords X1,Y1")
elseif input2 == "/List" or input2 == "/list" then
list = rednet.lookup(input3)
print(list)
--rednet.lookup(input3))
--elseif input2 == "/msg" then
--print("Enter ID")input1 = read()
--input1 = 18--"hi there"
--num = tonumber(input1)
--print("Enter Message") input2 = read()
--print(input1)
--rednet.send(input1,input2,input3)
--end
--elseif input2 == "/leave" then
--input3 = read()
--rednet.broadcast(string1)
--rednet.host("rougeminner's cell",input3)
--elseif input2 == not(nil) then
--rednet.broadcast(input2,input3)
--print("<ME>:",input2)
else
rednet.broadcast(input2,input3)
input2 = Base64.encode(AES.encrypt(key,input2))
print("<ME>:",input2)
end
else
end
end


Yes the code is very unorganized and hard to read right now. i have not had the time to fix with more organized code

Edited by Rougeminner, 30 November 2014 - 01:19 AM.


#42 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 30 November 2014 - 01:47 PM

View PostRougeminner, on 30 November 2014 - 01:16 AM, said:

what do you mean event corruption. i still get a java exception thrown error. Almost forgot heres my code
There is a bug in LuaJ which can result in any byte above 127 being corrupted. This is obvious when sending rednet, or saving to files. To prevent this you can base64 encode it.



Instead of doing:
Base64.decode(AES.decrypt(key,arg2))

we do

AES.decrypt(key, Base64.decode(arg2)) -- These should be swapped around

So we convert Hello to sfdhfjshdfjks which we base64 encode to c2ZkaGZqc2hkZmprcw==. We then run the process in reverse(b64 => encrypted => decrypted).

On a style guide, code is easier to read indented and you should really be using locals, but that isn't that important.

#43 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 20 December 2014 - 10:03 AM

I've just released a new version. I've rewritten the bit library to use native operations as much as possible. It now runs at 30 kB/s (which means this is now the fastest AES implementation on the forums). Due to better minification and bit library improvements, the code base is less than 12kB.

As ever the pastebin is 9E5UHiqv (DMx8M0LP for the unminfied version).

Edited by SquidDev, 20 December 2014 - 10:05 AM.


#44 Rokin05

  • Members
  • 8 posts

Posted 01 January 2015 - 05:14 PM

Hi, thank you for this script !
I'm beginner in CC and i have a problem, i don't know if it's me or the script, can you help me ? :

sample script for testing :

Computer1 (Client) :
os.loadAPI("AES")
os.loadAPI("Base64")

password = "1235"

-- plug monitor
local monitor = peripheral.find("monitor", function(name, object) object.side = name return true end)

-- plug modem
local modem = peripheral.find( "modem", function( name, obj ) return obj.isWireless() end)

msg = "Hello world !"
msg = AES.encrypt(password, msg)
msg = Base64.encode(msg)
           
modem.transmit(3, 1, msg)




Computer2 (Server) :
os.loadAPI("AES")
os.loadAPI("Base64")

password = "1235"

-- plug monitor
local monitor = peripheral.find("monitor", function(name, object) object.side = name return true end)

-- plug modem
local modem = peripheral.find( "modem", function( name, obj ) return obj.isWireless() end)

while true do
  modem.open(3)
  local event, modemSide, senderChannel,
  replyChannel, msg, senderDistance = os.pullEvent("modem_message")

  msg = Base64.decode(msg)
  msg = AES.decrypt(password, msg)
  monitor.write(msg)

  modem.closeAll()
end


So :

Computer 1 : msg -> AES -> Base64 -> ------------ channel 3 ------------- -> computer 2 -> Base64 -> AES -> read msg

ok if my AES password for crypt/decrypt is the same, its work good
now my problem it's if computer1 password != computer2 password my computer2 program halt and go back to the CC shell with this error : "Java exception thrown"


How can i fix it please ?


I have try with pastebin 9E5UHiqv and (DMx8M0LP for the unminfied version).
Direwolf 1.0.1 (1.7)
ComputerCraft1.65


thank tou !

#45 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 02 January 2015 - 04:47 PM

View PostRokin05, on 01 January 2015 - 05:14 PM, said:

-snip-

I've been unable to replicate this, I've updated the pastebin in case I've made changes and not updated it in the past but it should be fine.
Is there anything after "Java exception thrown"? Either a line number or a message.

Also I've written a little script (pastebin get MQ4jFFAQ trace) which can be used like trace myscript. This should provide a traceback or at least an error if something breaks. Can you tell me the output.

Edited by SquidDev, 02 January 2015 - 04:47 PM.


#46 Rokin05

  • Members
  • 8 posts

Posted 03 January 2015 - 12:14 PM

Thank you for your reply, my bad, after your post and 2h of try i have found my problem, it's not the AES api my problem it's just a big noob error :
(the trace script dont really help me because i don't return my problem, but after 150 "monitor.write" line per line i found it :D)


Client :
-- CLIENT
-- plug monitor
local monitor = peripheral.find("monitor", function(name, object) object.side = name return true end)
-- plug modem
local modem = peripheral.find( "modem", function( name, obj ) return obj.isWireless() end)

local password = "1234"

os.loadAPI("system/api/AES")
os.loadAPI("system/api/base64")

while true do
  write("send : ")
  msg= read()
  msg = AES.encrypt(password, msg)
  msg = base64.encode(msg)
		  
  modem.transmit(3, 1, msg)
end

Server :
-- SERVER1
-- plug monitor
local monitor = peripheral.find("monitor", function(name, object) object.side = name return true end)
-- plug modem
local modem = peripheral.find( "modem", function( name, obj ) return obj.isWireless() end)

local password = "imabadpwd"

os.loadAPI("system/api/AES")
os.loadAPI("system/api/base64")

function newLine()
  local _,cY= monitor.getCursorPos()
  monitor.setCursorPos(1,cY+1)
end

function monclear()
  monitor.clear()
  monitor.setCursorPos(1,1)
end

while true do
  modem.open(3)
 
  local event, modemSide, senderChannel,
  replyChannel, msg, senderDistance = os.pullEventRaw("modem_message")
  monclear()
  monitor.write("Base64: "..msg)
  msg = base64.decode(msg)
 
  newLine()
  monitor.write("AES: "..msg)
  msg = AES.decrypt(password, msg)
 
  newLine()
  if msg == nil then msg = "error" end
 
  monitor.write("MSG : "..msg)
  modem.closeAll()
end


the problem :
msg = AES.decrypt(password, msg)
[color=#FF0000]monitor.write("MSG : "..msg) -- error ([/color][color=#FF0000]msg = nil)[/color]




with script like that, its good :

msg = AES.decrypt(password, msg)
[color=#008000]if msg == nil then msg = "decrypt error (bad pwd)" end[/color]



monitor.write("MSG : "..msg)


:rolleyes: thank you !

#47 Phaneron

  • Members
  • 3 posts

Posted 11 August 2015 - 04:24 AM

I've tried to load and use the program, but I keep running into odd errors. Could anybody illuminate me as to what I am doing wrong? ComputerCraft 1.73Posted Image

Edited by Phaneron, 11 August 2015 - 05:37 AM.


#48 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 11 August 2015 - 06:50 AM

View PostPhaneron, on 11 August 2015 - 04:24 AM, said:

I've tried to load and use the program, but I keep running into odd errors. Could anybody illuminate me as to what I am doing wrong? ComputerCraft 1.73

From what I can tell, the issue comes with printing 'unprintable' characters. If you call AES.util.toHexString(AES.encrypt("key", "message")) then it shouldn't error. However, due to changes in the Bit API decryption is currently broken in CC 1.74 so be warned. I'm looking into fixing it but have so many projects on the go right now I haven't got round to fixing it. Sorry.

#49 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 12 September 2015 - 10:25 PM

Hey, just checking here too see if you've updated this for the latest version of CC, if I remember correctly it wasn't working too well with the changes made to the bit API or something right? So yeah, have you updated this? I'm not that active on github so I haven't checked there for any changes recently.

#50 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 15 September 2015 - 12:00 PM

View PostTheOddByte, on 12 September 2015 - 10:25 PM, said:

Hey, just checking here too see if you've updated this for the latest version of CC, if I remember correctly it wasn't working too well with the changes made to the bit API or something right?

Ahhh, no. What I'll do for the time being is roll back to the old bit API I was using, which is slower but works with CC 1.74, and then try to bugfix. Sorry.

Edited by SquidDev, 15 September 2015 - 12:00 PM.


#51 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 15 September 2015 - 03:49 PM

View PostSquidDev, on 15 September 2015 - 12:00 PM, said:

View PostTheOddByte, on 12 September 2015 - 10:25 PM, said:

Hey, just checking here too see if you've updated this for the latest version of CC, if I remember correctly it wasn't working too well with the changes made to the bit API or something right?

Ahhh, no. What I'll do for the time being is roll back to the old bit API I was using, which is slower but works with CC 1.74, and then try to bugfix. Sorry.

Right, fixed. I didn't have to roll back to the old system, though I've dropped from 30kb/s to 26kb/s which isn't ideal. I'm hoping the bit library changes will be fixed, but I'll have to wait and see :).

#52 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 16 September 2015 - 06:33 PM

View PostSquidDev, on 15 September 2015 - 03:49 PM, said:

- snip -
Great to hear that it's working atleast.

#53 TrumpetMiner

  • Members
  • 33 posts

Posted 14 December 2015 - 10:48 PM

When I send an encrypted message to another computer it cannot decrypt. Am I doing something wrong?

#54 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 15 December 2015 - 01:10 PM

View PostTrumpetMiner, on 14 December 2015 - 10:48 PM, said:

When I send an encrypted message to another computer it cannot decrypt. Am I doing something wrong?

You'll have to encode the string in some way - CC cannot send binary data across modems. The easiest way to do it would be to encode it in base64 before sending, and decode before decrypting it.

#55 TrumpetMiner

  • Members
  • 33 posts

Posted 16 December 2015 - 11:29 PM

View PostSquidDev, on 15 December 2015 - 01:10 PM, said:

View PostTrumpetMiner, on 14 December 2015 - 10:48 PM, said:

When I send an encrypted message to another computer it cannot decrypt. Am I doing something wrong?

You'll have to encode the string in some way - CC cannot send binary data across modems. The easiest way to do it would be to encode it in base64 before sending, and decode before decrypting it.

What would be a good way to encode and decode in base64?

#56 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 16 December 2015 - 11:54 PM

I use this. (Or at least, most of that. I don't use the command line part)

Edited by KingofGamesYami, 16 December 2015 - 11:55 PM.


#57 TrumpetMiner

  • Members
  • 33 posts

Posted 19 December 2015 - 08:23 PM

View PostKingofGamesYami, on 16 December 2015 - 11:54 PM, said:

I use this. (Or at least, most of that. I don't use the command line part)

Thanks, this works great!

#58 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 11 April 2016 - 04:16 PM

Just pushed an update to this with several changes:
  • Allow passing the IV through the main API. I'd recommend this for additional security
  • Add CTR mode. Almost 2 years after Anavrins asked for it. Sorry :(.
  • 143 unit tests! All the NIST test vectors pass.
I've also moved the code to a Gist as it is easier for me to keep up to date. If anyone is pointing this at the pastebin code then please switch to the Gist link.

Edited by SquidDev, 11 April 2016 - 04:23 PM.


#59 randomdude999

  • Members
  • 19 posts
  • LocationStar System Sol, Galactic Sector ZZ9 Plural Z Alpha

Posted 22 May 2016 - 08:40 AM

Hey, I just made installing it even easier:
wget https://git.io/aeslua aeslua
If you don't have wget:
pastebin run xLRDQj9t https://git.io/aeslua aeslua

Edited by randomdude999, 22 May 2016 - 08:49 AM.


#60 SquidDev

    Frickin' laser beams | Resident Necromancer

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

Posted 22 May 2016 - 09:33 AM

View Postrandomdude999, on 22 May 2016 - 08:40 AM, said:

-snip-

Whoah, thanks! Didn't know this was a thing. Updated the OP with this.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users