des加密 lua

编程入门 行业动态 更新时间:2024-10-07 06:39:42

<a href=https://www.elefans.com/category/jswz/34/1770421.html style=des加密 lua"/>

des加密 lua

分享2种openresty des3加密的代码,节省大家脱坑的时间:

1.based on lua-resty-nettle

local pkcs7 = require "restytle.padding.pkcs7"

local base64 = require "restytle.base64"

local des = require "restytle.des"

local cipher= des.new("密钥")

local encrypted = cipher:encrypt(pkcs7.pad('要加密的文本', 8))

ngx.print(base64.encode(encrypted))

2.based on lua-lockbox

local Array = require("lockbox.util.array")

local Stream = require("lockbox.util.stream")

local ECBMode = require("lockbox.cipher.mode.ecb")

local PKCS7Padding = require("lockbox.padding.pkcs7")

local DESCipher = require("lockbox.cipher.des3")

local Base64 = require("lockbox.util.base64")

local cipher = ECBMode.Cipher().setKey(Array.fromString("密钥")).setBlockCipher(DESCipher).setPadding(PKCS7Padding)

local res = cipher.init().update(Stream.fromArray(Array.fromString(""))).update(Stream.fromArray(Array.fromString('要加密的文本'))).finish().asBytes()

local out = Base64.fromArray(res)

ngx.print(out)

推荐第1种,性能还可以,lua-lockbox需要修改lockbox.padding.pkcs7中的一行代码local paddingCount = blockSize - byteCount % blockSize;

更多推荐

des加密 lua

本文发布于:2024-02-07 00:28:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1751965.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:des   lua

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!