2021-08-09 17:43:42 +02:00
|
|
|
local lu = require("luaunit")
|
|
|
|
local aes = require("resty.openssl.cipher")
|
|
|
|
|
|
|
|
function test_aes()
|
2023-08-18 22:24:34 +02:00
|
|
|
local key1 = "0a123456789a123456789a1234567890"
|
|
|
|
local key2 = "0b123456789b123456789b1234567890"
|
2021-08-09 17:43:42 +02:00
|
|
|
local aes1 = aes.new(nil)
|
|
|
|
local aes2 = aes.new(nil)
|
2023-08-18 22:24:34 +02:00
|
|
|
local enc1 = assert(aes1:encrypt(key1, "iv", "test", nil, "test"))
|
|
|
|
local enc2 = assert(aes2:encrypt(key2, "iv", "other", nil, "test"))
|
2021-08-09 17:43:42 +02:00
|
|
|
local tag1 = aes1:get_aead_tag()
|
|
|
|
local tag2 = aes2:get_aead_tag()
|
|
|
|
local aes3 = aes.new(nil)
|
|
|
|
local aes4 = aes.new(nil)
|
|
|
|
lu.assertEquals(#tag1, 16)
|
|
|
|
lu.assertEquals(#tag2, 16)
|
|
|
|
lu.assertNotEquals(enc1, "test")
|
|
|
|
lu.assertNotEquals(enc2, "other")
|
|
|
|
lu.assertNotEquals(enc1 .. tag1, "test")
|
|
|
|
lu.assertNotEquals(enc2 .. tag2, "other")
|
2023-08-18 22:24:34 +02:00
|
|
|
lu.assertEquals(aes3:decrypt(key1, "iv", enc1, nil, "test", tag1), "test")
|
|
|
|
lu.assertEquals(aes4:decrypt(key2, "iv", enc2, nil, "test", tag2), "other")
|
2021-08-09 17:43:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
os.exit(lu.LuaUnit.run())
|