Skip to content

Instantly share code, notes, and snippets.

@CandyMi
Last active April 30, 2024 05:43
Show Gist options
  • Save CandyMi/c76466635bb1d63becacd32379d4fac3 to your computer and use it in GitHub Desktop.
Save CandyMi/c76466635bb1d63becacd32379d4fac3 to your computer and use it in GitHub Desktop.
中宣接口示例代码

中宣接口加密解密测试代码

local crypto = require "crypt"
-- local key = crypto.hexdecode('2836e95fcd10e04b0069bb1ee659955b')
-- local data = crypto.base64decode('CqT/33f3jyoiYqT8MtxEFk3x2rlfhmgzhxpHqWosSj4d3hq2EbrtVyx2aLj565ZQNTcPrcDipnvpq/D/vQDaLKW70O83Q42zvR0//OfnYLcIjTPMnqa+SOhsjQrSdu66ySSORCAo')
local key = crypto.hexdecode('e73d41b84ac68dc27b56355800fb0011')
local data = crypto.base64decode('kHk2llJk6dLH23tlX4X/erAs/lqqt2RUA3Wclm9XOjuO9P8Qk7Db7H/BTE1YXktR3uu1PI3XJu94bl/ssY/aMqpKsA+JSV68s6Ez4AuNDrsqnh4Y/mzKcLxeUOMwH2ZueDTImrboNQ==')
local iv, cipher = data:sub(1, 12), data:sub(13)
print('iv', crypto.hexencode(iv))
print(crypto.aes_128_gcm_decrypt(key, cipher, iv, "", 16))
-- print(crypto.aes_128_gcm_decrypt(key, cipher, iv, "", 16) == '{"ai":"100000000000000001","name":"某一一","idNum":"110000190101010001"}')
local crypto = require "crypt"
-- local text = '{"ai":"100000000000000001","name":"某一一","idNum":"110000190101010001"}'
-- local key = crypto.hexdecode 'e73d41b84ac68dc27b56355800fb0011'
-- local iv = crypto.hexdecode '907936965264e9d2c7db7b65'
local text = '{"ai":"test-accountId","name":"用户姓名","idNum":"371321199012310912"}'
local key = crypto.hexdecode '2836e95fcd10e04b0069bb1ee659955b'
local iv = crypto.hexdecode '0aa4ffdf77f78f2a2262a4fc'
local data = crypto.aes_128_gcm_encrypt(key, text, iv, "", 16)
print(crypto.base64encode(iv .. data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment