add padding mode for DES, see #1179

This commit is contained in:
Cloud Wu
2020-04-23 11:45:35 +08:00
parent 22f25bad55
commit 2389772c73
2 changed files with 130 additions and 22 deletions

24
test/testcrypt.lua Normal file
View File

@@ -0,0 +1,24 @@
local skynet = require "skynet"
local crypt = require "skynet.crypt"
local text = "hello world"
local key = "12345678"
local function desencode(key, text, padding)
local c = crypt.desencode(key, text, crypt.padding[padding or "iso7816_4"])
return crypt.base64encode(c)
end
local function desdecode(key, text, padding)
text = crypt.base64decode(text)
return crypt.desdecode(key, text, crypt.padding[padding or "iso7816_4"])
end
local etext = desencode(key, text)
assert( etext == "KNugLrX23UcGtcVlk9y+LA==")
assert(desdecode(key, etext) == text)
local etext = desencode(key, text, "pkcs7")
assert(desdecode(key, etext, "pkcs7") == text)
skynet.start(skynet.exit)