为啥对不上?好奇怪
1 、openresty github 官方示例
https://github.com/openresty/lua-resty-string
local aes = require "resty.aes"
local str = require "resty.string"
local aes_128_cbc_md5 = aes:new("AKeyForAES")
-- the default cipher is AES 128 CBC with 1 round of MD5
-- for the key and a nil salt
local encrypted = aes_128_cbc_md5:encrypt("Secret message!")
ngx.say("AES 128 CBC (MD5) Encrypted HEX: ", str.to_hex(encrypted))
ngx.say("AES 128 CBC (MD5) Decrypted: ", aes_128_cbc_md5:decrypt(encrypted))
2 、自己编写 lua 测试
local aes = require "resty.aes"
local str = require "resty.string"
local aes_128_cbc_md5 = aes:new("gOxiO7IIRthJ406X")
-- the default cipher is AES 128 CBC with 1 round of MD5
-- for the key and a nil salt
local encrypted = aes_128_cbc_md5:encrypt("hello")
ngx.say("AES 128 CBC (MD5) Encrypted HEX: ", str.to_hex(encrypted))
ngx.say("AES 128 CBC (MD5) Decrypted: ", aes_128_cbc_md5:decrypt(encrypted))
-- 输出结果
AES 128 CBC (MD5) Encrypted HEX: de6641e8a49ef1911a10d9ec88cc477b
AES 128 CBC (MD5) Decrypted: hello
3 、java 实现
@Test
public void testEncryptText() {
String key = "gOxiO7IIRthJ406X";
byte[] iv = new byte[16];
String text = "hello";
AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, SecureUtil.md5(key).getBytes(), iv);
System.out.println(aes.encryptHex(text));
// 输出:446d1192d40aa0d05e3c30392ac43ec3
aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv);
System.out.println(aes.encryptHex(text));
// 输出:190ede3e1359a6e4d8ecf38c8f4bce63
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.