Giter Club home page Giter Club logo

lua-resty-des's Introduction

this repo finished a DES ECB encrypt/decryption method. for now just DES/EBC is tested. more test and pull request is welcomed.

this Tencent qcloud HTTPDNS servier DES ECB padding5 encryption API,where you can verify you result http://119.29.29.29/en?v=www.google.com&k=weijianliao key: weijianliao result: cd52888ecabcac455a14ddbac7f03d97

you can just test with resty CLI

root@localhost:~# resty lua_func_test.lua 
cd52888ecabcac455a14ddbac7f03d97
decode:www.google.com

example in Java

try {
//init key 
SecretKeySpec keySpec = new SecretKeySpec(encKey.getBytes("utf-8"), "DES");
//choose DES £¬ECB mode£¬ PKCS5Padding
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
//init
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
//get encrypted string
encryptedString = bytesToHex(cipher.doFinal(hostName.getBytes("utf-8")));
} catch (Exception e) {
e.printStackTrace();
}

example code in PHP

/**
 * des-ecb½âÃÜ
 * @param string  $data data need encrypted
 * @param string  $key encrypted key
 */
function des_ecb_decrypt ($data, $key){
    return openssl_decrypt ($data, 'des-ecb', $key);
}

$str = 'www.google.com';  
$key = 'weijianliao';   
$res = des_ecb_encrypt($str, $key);   
echo bin2hex(base64_decode($res))."\n";  
// result is=cd52888ecabcac455a14ddbac7f03d97
  

lua-resty-des's People

Contributors

lilien1010 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lua-resty-des's Issues

des不加密 解密返回nil

您好,我这边由第三方加密 我自己这边解密。发现调用des.lua解密不了 直接返回nil 请问有解决方式吗?
源码看了下 表示看不懂 - -!
希望能得到您的回复。
代码:
local key ="QH8aYq4d"
local salt =nil
desMod,err = des:new(key,salt)
local result = desMod:decrypt("780d5486e73a75cc5b535e705d8fe6fd078b65cd5bcd15a5")
得到的result为nil
应该解出来的result为121235/UuYsC3282
对了源码cipher我默认改为了cbc模式

undefined symbol: EVP_CIPHER_CTX_cleanup

resty 0.27
nginx version: openresty/1.19.3.1
built by gcc 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
built with OpenSSL 1.1.1h 22 Sep 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.19 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../ngx_stream_lua-0.0.9 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --with-cc='ccache gcc -fdiagnostics-color=always' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.