|
@@ -49,15 +49,23 @@ sys.taskInit(function()
|
|
|
|
|
|
|
|
-- DES-ECB 加解密
|
|
-- DES-ECB 加解密
|
|
|
local data1 = crypto.cipher_encrypt("DES-ECB", "PKCS7", "abcdefg", "12345678")
|
|
local data1 = crypto.cipher_encrypt("DES-ECB", "PKCS7", "abcdefg", "12345678")
|
|
|
- print(data1:toHex())
|
|
|
|
|
- local data2 = crypto.cipher_decrypt("DES-ECB", "PKCS7", data1, "12345678")
|
|
|
|
|
- print(data2)
|
|
|
|
|
|
|
+ if data1 then -- DES-ECB 在某些平台不支持的
|
|
|
|
|
+ print(data1:toHex())
|
|
|
|
|
+ local data2 = crypto.cipher_decrypt("DES-ECB", "PKCS7", data1, "12345678")
|
|
|
|
|
+ print(data2)
|
|
|
|
|
+ end
|
|
|
|
|
|
|
|
-- 打印所有支持的cipher
|
|
-- 打印所有支持的cipher
|
|
|
if crypto.cipher_list then
|
|
if crypto.cipher_list then
|
|
|
log.info("cipher", "list", json.encode(crypto.cipher_list()))
|
|
log.info("cipher", "list", json.encode(crypto.cipher_list()))
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ for i=1, 10 do
|
|
|
|
|
+ sys.wait(100)
|
|
|
|
|
+ log.info("crypto", "真随机数",string.unpack("I",crypto.trng(4)))
|
|
|
|
|
+ log.info("crypto", "伪随机数",math.random())
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
-- totp的密钥
|
|
-- totp的密钥
|
|
|
local secret = "VK54ZXPO74ISEM2E"
|
|
local secret = "VK54ZXPO74ISEM2E"
|
|
|
--写死时间戳用来测试
|
|
--写死时间戳用来测试
|
|
@@ -66,9 +74,11 @@ sys.taskInit(function()
|
|
|
for i=1,600,30 do
|
|
for i=1,600,30 do
|
|
|
local r = crypto.totp(secret,ts+i)
|
|
local r = crypto.totp(secret,ts+i)
|
|
|
local time = os.date("*t",ts+i + 8*3600)--东八区
|
|
local time = os.date("*t",ts+i + 8*3600)--东八区
|
|
|
- log.info("totp",r,time.hour,time.min,time.sec)
|
|
|
|
|
|
|
+ log.info("totp", string.format("%06d" ,r),time.hour,time.min,time.sec)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ log.info("crypto", "ALL Done")
|
|
|
|
|
+ sys.wait(100000)
|
|
|
end)
|
|
end)
|
|
|
|
|
|
|
|
-- 用户代码已结束---------------------------------------------
|
|
-- 用户代码已结束---------------------------------------------
|