Giter VIP home page Giter VIP 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
  

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.