initialize commit
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..141515e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+/target
+Cargo.lock
+*.dylib
+*.so
+.gradle
+build
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..7645052
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,2 @@
+[workspace]
+members = ["daliqrcode", "dlsmk"]
diff --git a/daliqrcode/Cargo.toml b/daliqrcode/Cargo.toml
new file mode 100644
index 0000000..e51e7eb
--- /dev/null
+++ b/daliqrcode/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "dlqrcode"
+version = "0.1.0"
+authors = ["Tang Cheng <cheng.tang@supwisdom.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+block-modes = "0.7.0"
+aes = "0.6.0"
+base64 = "0.13.0"
+sha2 = "0.9.1"
+totp-rs = "0.6.2"
+hex = "0.4.2"
+base64-url = "1.4.7"
+
+[dependencies.magic-crypt]
+version = "*"
+default-features = false
diff --git a/daliqrcode/src/lib.rs b/daliqrcode/src/lib.rs
new file mode 100644
index 0000000..9bb1114
--- /dev/null
+++ b/daliqrcode/src/lib.rs
@@ -0,0 +1,397 @@
+extern crate base64_url;
+extern crate hex;
+
+use std::fmt;
+use std::slice;
+use std::time::Instant;
+use std::time::SystemTime;
+
+use sha2::{Digest, Sha256};
+
+use aes::Aes256;
+use block_modes::block_padding::Pkcs7;
+use block_modes::{BlockMode, Cbc};
+use totp_rs::{Algorithm, TOTP};
+
+type Aes256Cbc = Cbc<Aes256, Pkcs7>;
+
+const TOTP_STEP: u64 = 5;
+const TOTP_SKEW: u8 = 3;
+static QR_FIELD_DILIMITER: &str = ":";
+
+pub struct DaliQrCode {
+    master_key: Vec<u8>,
+    iv: Vec<u8>,
+    totp_step: u64,
+    totp_skew: u8,
+    totp_seed: Vec<u8>,
+}
+
+#[derive(Debug)]
+pub struct DaliQrData {
+    pub uid: String,
+    pub cardno: String,
+    pub cardtype: String,
+    pub totp: String,
+    pub nonce: String,
+    sign: Vec<u8>,
+}
+
+impl DaliQrData {
+    fn new() -> Self {
+        Self {
+            uid: String::from(""),
+            cardno: String::from(""),
+            cardtype: String::from(""),
+            totp: String::from(""),
+            nonce: String::from(""),
+            sign: Vec::new(),
+        }
+    }
+
+    fn from_qrcode(qr_fields: &Vec<Vec<u8>>) -> Result<Self> {
+        if qr_fields.len() < 6 {
+            return Err(DecodeError::new("qrcode fields length must grater than 6."));
+        }
+        let sign = qr_fields[5].to_vec();
+        Ok(Self {
+            uid: String::from_utf8_lossy(&qr_fields[0].as_slice()).to_string(),
+            cardno: String::from_utf8_lossy(&qr_fields[1].as_slice()).to_string(),
+            cardtype: String::from_utf8_lossy(&qr_fields[2].as_slice()).to_string(),
+            totp: String::from_utf8_lossy(&qr_fields[3].as_slice()).to_string(),
+            nonce: String::from_utf8_lossy(&qr_fields[4].as_slice()).to_string(),
+            sign: sign,
+        })
+    }
+
+    fn update_sign(&mut self, sign: &Vec<u8>) {
+        self.sign = sign.to_vec();
+    }
+
+    fn to_qrdata(&self) -> String {
+        let v = vec![
+            String::from(&self.uid),
+            String::from(&self.cardno),
+            String::from(&self.cardtype),
+            String::from(&self.totp),
+            String::from(&self.nonce),
+        ];
+        v.join(QR_FIELD_DILIMITER)
+    }
+}
+
+#[derive(Debug, Clone)]
+pub struct DecodeError {
+    message: String,
+}
+
+impl fmt::Display for DecodeError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "Decode Qrcode error {}", self.message)
+    }
+}
+
+impl DecodeError {
+    fn new(message: &str) -> Self {
+        Self {
+            message: String::from(message),
+        }
+    }
+}
+
+type Result<T> = std::result::Result<T, DecodeError>;
+
+const KEY_LEN: usize = 32;
+impl DaliQrCode {
+    pub fn new(
+        key: [u8; KEY_LEN],
+        iv: Option<[u8; 16]>,
+        step: Option<u64>,
+        skew: Option<u8>,
+        seed: Option<Vec<u8>>,
+    ) -> Result<Self> {
+        let key = key.to_vec();
+        if key.len() != KEY_LEN {
+            return Err(DecodeError::new(&format!(
+                "key size must be {} bytes",
+                KEY_LEN
+            )));
+        }
+        let iv = if let Some(v) = iv {
+            v.to_vec()
+        } else {
+            hex::decode("55b6f5b3287c535f8274b99354676d0e").unwrap()
+        };
+
+        if iv.len() != 16 {
+            return Err(DecodeError::new("IV size must be 16 bytes"));
+        }
+
+        let step = if let Some(s) = step { s } else { TOTP_STEP };
+
+        let skew = if let Some(s) = skew { s } else { TOTP_SKEW };
+
+        let seed = if let Some(s) = seed {
+            s
+        } else {
+            hex::decode("125ea2f97689988b6501").unwrap()
+        };
+
+        Ok(Self {
+            master_key: key,
+            iv: iv,
+            totp_seed: seed,
+            totp_skew: skew,
+            totp_step: step,
+        })
+    }
+
+    pub fn decode(&self, qrcode: *const u8, len: usize, secs_offset: i32) -> Result<DaliQrData> {
+        let qrcode = match self.decode_qrcode(qrcode, len) {
+            Ok(q) => q,
+            Err(e) => return Err(e),
+        };
+        let mut qr_fields: Vec<Vec<u8>> = Vec::new();
+        let v = QR_FIELD_DILIMITER.as_bytes()[0];
+        let mut j = 0;
+        for i in 0..qrcode.len() {
+            if qrcode[i] == v {
+                if i > j {
+                    let mut s = Vec::new();
+                    s.extend_from_slice(&qrcode[j..i]);
+                    qr_fields.push(s);
+                }
+                j = i + 1;
+            }
+        }
+        if j < qrcode.len() {
+            let mut s = Vec::new();
+            s.extend_from_slice(&qrcode[j..]);
+            qr_fields.push(s);
+        }
+        let qr_data = match DaliQrData::from_qrcode(&qr_fields) {
+            Ok(d) => d,
+            Err(e) => return Err(e),
+        };
+
+        match self.check_qrcode_sign(&qr_data) {
+            Ok(result) if !result => return Err(DecodeError::new("invalidate qrcode")),
+            Ok(_) => (),
+            Err(e) => return Err(e),
+        }
+
+        let totp = self.new_totp();
+        let time = self.totp_time(secs_offset);
+        if totp.check(&qr_data.totp, time) {
+            Ok(qr_data)
+        } else {
+            Err(DecodeError::new("qrcode totp error"))
+        }
+    }
+
+    fn check_qrcode_sign(&self, qr_data: &DaliQrData) -> Result<bool> {
+        let sign = self.calc_sign(qr_data);
+        if qr_data.sign == sign {
+            Ok(true)
+        } else {
+            Ok(false)
+        }
+    }
+
+    fn decode_qrcode(
+        &self,
+        qrcode: *const u8,
+        len: usize,
+    ) -> std::result::Result<Vec<u8>, DecodeError> {
+        let cipher = match Aes256Cbc::new_var(&self.master_key, &self.iv) {
+            Ok(c) => c,
+            Err(e) => return Err(DecodeError::new(&format!("aes key error {:?}", e))),
+        };
+
+        let qrcode = unsafe {
+            let s = slice::from_raw_parts(qrcode, len);
+            println!("qr input : {}", String::from_utf8_lossy(s));
+            if let Ok(code) = base64_url::decode(s) {
+                code
+            } else {
+                return Err(DecodeError::new("data base64 decode error"));
+            }
+        };
+
+        if qrcode.len() % 16 != 0 {
+            return Err(DecodeError::new("Input data length error"));
+        }
+
+        match cipher.decrypt_vec(&qrcode) {
+            Ok(data) => Ok(data),
+            Err(e) => Err(DecodeError::new(&format!("block error {:?}", e))),
+        }
+    }
+
+    fn totp_time(&self, secs_offset: i32) -> u64 {
+        let time = SystemTime::now()
+            .duration_since(SystemTime::UNIX_EPOCH)
+            .unwrap()
+            .as_secs();
+        if secs_offset > 0 {
+            time + (secs_offset as u64)
+        } else {
+            time - (secs_offset as u64)
+        }
+    }
+
+    fn new_totp(&self) -> TOTP<Vec<u8>> {
+        let seed = self.totp_seed.clone();
+        TOTP::new(Algorithm::SHA1, 8, self.totp_skew, self.totp_step, seed)
+    }
+
+    fn encode_qrcode(&self, qr_data: &DaliQrData) -> Result<String> {
+        let plain_text = qr_data.to_qrdata();
+        let cipher = match Aes256Cbc::new_var(&self.master_key, &self.iv) {
+            Ok(c) => c,
+            Err(e) => return Err(DecodeError::new(&format!("aes key error {:?}", e))),
+        };
+        let mut buffer = Vec::new();
+        buffer.extend_from_slice(&plain_text.as_bytes());
+        buffer.push(QR_FIELD_DILIMITER.as_bytes()[0]);
+        buffer.extend_from_slice(qr_data.sign.as_slice());
+        let crypt_data = cipher.encrypt_vec(buffer.as_slice());
+        Ok(base64_url::encode(crypt_data.as_slice()))
+    }
+
+    fn calc_sign(&self, qr_data: &DaliQrData) -> Vec<u8> {
+        let mut hasher = Sha256::new();
+        hasher.update("{dlsmk_}".as_bytes());
+        hasher.update(qr_data.uid.as_bytes());
+        let salt = hasher.finalize();
+        let mut hasher = Sha256::new();
+        hasher.update(qr_data.to_qrdata().as_bytes());
+        hasher.update(salt);
+        hasher.finalize().to_vec()
+    }
+
+    pub fn encode(&self, qr_data: &mut DaliQrData, secs_offset: i32) -> Result<String> {
+        if qr_data.nonce.len() == 0 {
+            qr_data.nonce = format!("{:02}", Instant::now().elapsed().as_secs() % 100);
+        }
+        if qr_data.totp.len() == 0 {
+            let totp = self.new_totp();
+            let time = self.totp_time(secs_offset);
+            qr_data.totp = totp.generate(time);
+        }
+        let sign = self.calc_sign(qr_data);
+        qr_data.update_sign(&sign);
+        self.encode_qrcode(qr_data)
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use base64::decode;
+    use std::convert::TryInto;
+    const KEYLEN: usize = 32;
+    #[test]
+    fn it_works() {
+        assert_eq!(2 + 2, 4);
+    }
+
+    #[test]
+    fn aes_test() {
+        let mut key = [0u8; KEYLEN];
+        let s = decode("Vbb1syh8U1+CdLmTVGdtDiVvKBQ81n4GmgBEO/ohSbU=").unwrap();
+        key.clone_from_slice(&s.as_slice()[..KEYLEN]);
+
+        let iv: [u8; 16] = {
+            let s = hex::decode("55b6f5b3287c535f8274b99354676d0e").unwrap();
+            s.into_boxed_slice().as_ref().try_into().unwrap()
+        };
+
+        let aes_key = Aes256Cbc::new_var(&key, &iv).unwrap();
+        let plaintext = String::from("hello ldldldf ldfldl dslfasdamf sdmfdfdf");
+
+        let mut buffer = Vec::new();
+        buffer.extend_from_slice(plaintext.as_bytes());
+        println!(
+            "plain len : {} , buffer len : {}",
+            plaintext.len(),
+            buffer.len()
+        );
+        let cipher_data = aes_key.encrypt_vec(&buffer);
+
+        println!(
+            "cipher len : {}, last {}",
+            cipher_data.len(),
+            cipher_data[cipher_data.len() - 1] as u32
+        );
+
+        let aes_key = Aes256Cbc::new_var(&key, &iv).unwrap();
+        let _ = aes_key.decrypt_vec(&cipher_data);
+    }
+
+    fn get_key() -> ([u8; KEYLEN], [u8; 16]) {
+        let mut key = [0u8; KEYLEN];
+        let s = decode("Vbb1syh8U1+CdLmTVGdtDiVvKBQ81n4GmgBEO/ohSbU=").unwrap();
+        key.clone_from_slice(&s.as_slice()[..KEYLEN]);
+
+        let iv: [u8; 16] = {
+            let s = hex::decode("55b6f5b3287c535f8274b99354676d0e").unwrap();
+            s.into_boxed_slice().as_ref().try_into().unwrap()
+        };
+        (key, iv)
+    }
+
+    #[test]
+    fn check_qrcode_encode() {
+        let expect_qrcode = String::from("6lHyFX_vg5U2hymn8OsdNUD7dT0-sCmEQkKrm9cnzHlku6-FYxuL6nP5YR2Fve8Sfj-Asd-3dfQUkaiqqbfQWO8B_811B3uhHmGm9IjlpLicz_c1H1_ORb9tJl-IhMKu");
+        // let buffer = base64_url::decode(expect_qrcode.as_bytes()).unwrap();
+
+        // println!("encrypt buffer <{}>", buffer.len());
+        // println!("decode b64<{}>", hex::encode(buffer.clone()));
+        // let aes_key = Aes256Cbc::new_var(&key, &iv).unwrap();
+        // let data = aes_key.decrypt_vec(&buffer).unwrap();
+        // println!("data : {}", String::from_utf8_lossy(data.as_slice()));
+
+        let (key, iv) = get_key();
+
+        let mut qr_data = DaliQrData::new();
+        qr_data.uid = String::from("0a5de6ce985d43989b7ebe64ad8eb9c3");
+        qr_data.cardno = String::from("00001252");
+        qr_data.cardtype = String::from("80");
+        qr_data.nonce = String::from("ac");
+        qr_data.totp = String::from("50053019");
+
+        let dali_qrcode = DaliQrCode::new(key, Some(iv), None, None, None).unwrap();
+
+        match dali_qrcode.encode(&mut qr_data, 0) {
+            Ok(qrcode) => {
+                assert_eq!(qrcode, expect_qrcode);
+            }
+            Err(e) => {
+                panic!("error {}", e);
+            }
+        }
+    }
+
+    #[test]
+    fn check_qrcode_decode() {
+        let (key, iv) = get_key();
+        let mut qr_data = DaliQrData::new();
+        qr_data.uid = String::from("0a5de6ce985d43989b7ebe64ad8eb9c3");
+        qr_data.cardno = String::from("00001252");
+        qr_data.cardtype = String::from("80");
+
+        let dali_qrcode = DaliQrCode::new(key, Some(iv), None, None, None).unwrap();
+
+        match dali_qrcode.encode(&mut qr_data, 0) {
+            Ok(qrcode) => {
+                if let Err(e) = dali_qrcode.decode(qrcode.as_ptr(), qrcode.len(), 0) {
+                    panic!("error {}", e);
+                }
+            }
+            Err(e) => {
+                panic!("error {}", e);
+            }
+        }
+    }
+}
diff --git a/dlsmk/Cargo.toml b/dlsmk/Cargo.toml
new file mode 100644
index 0000000..4042d47
--- /dev/null
+++ b/dlsmk/Cargo.toml
@@ -0,0 +1,19 @@
+[package]
+name = "dlsmk"
+version = "0.1.0"
+authors = ["Tang Cheng <cheng.tang@supwisdom.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[target.'cfg(target_os="android")'.dependencies]
+jni = { version = "0.18.0", default-features = false }
+
+[lib]
+crate-type = ["cdylib"]
+
+[dependencies]
+jni = "0.18.0"
+dlqrcode = { path = "../daliqrcode" }
+libc = "0.2.80"
+hex = "0.4.2"
diff --git a/dlsmk/src/lib.rs b/dlsmk/src/lib.rs
new file mode 100644
index 0000000..402a0c0
--- /dev/null
+++ b/dlsmk/src/lib.rs
@@ -0,0 +1,108 @@
+#[cfg(test)]
+mod tests {
+    #[test]
+    fn it_works() {
+        assert_eq!(2 + 2, 4);
+    }
+}
+
+// use std::ffi::{CStr, CString};
+// use std::os::raw::{c_char, c_uchar, c_ulong};
+
+// #[no_mangle]
+// pub extern "C" fn dlsmk_decode(
+//     key: *const c_uchar,
+//     qrcode: *const c_uchar,
+//     qrlen: c_ulong,
+// ) -> *mut c_char {
+//     CString::new("Hello ".to_owned()).unwrap().into_raw()
+// }
+
+// #[cfg(target_os = "android")]
+#[cfg(any(target_family = "unix", target_os = "android"))]
+// #[cfg(target_family = "unix")]
+#[allow(non_snake_case)]
+pub mod android {
+    extern crate jni;
+
+    use self::jni::objects::{JClass, JObject, JString};
+    use self::jni::sys::{jboolean, jlong, JNI_FALSE, JNI_TRUE};
+    use self::jni::JNIEnv;
+    // use super::*;
+    use libc;
+    use std::slice;
+
+    use dlqrcode::DaliQrCode;
+
+    #[no_mangle]
+    pub unsafe extern "C" fn Java_com_supwisdom_dlsmk_DLSMKQrCode_decode(
+        env: JNIEnv,
+        _: JClass,
+        key_hex: JString,
+        qrcode: JString,
+        offset: jlong,
+        result: JObject,
+    ) -> jboolean {
+        // Our Java companion code might pass-in "world" as a string, hence the name.
+        let key = env
+            .get_string(key_hex)
+            .expect("invalid key string")
+            .as_ptr();
+        let keylen = libc::strlen(key);
+
+        println!("decode test, key length {}", keylen);
+        let key = {
+            let k: &[u8] = slice::from_raw_parts(key as *const u8, keylen);
+            println!("key is : {}", String::from_utf8_lossy(k));
+            let mut key = [0u8; 32];
+            if let Ok(v) = hex::decode(k) {
+                key.clone_from_slice(v.as_slice());
+                key
+            } else {
+                return JNI_FALSE;
+            }
+        };
+
+        let qrcode = env
+            .get_string(qrcode)
+            .expect("invalid qrcode string")
+            .as_ptr();
+        let qrlen = libc::strlen(qrcode);
+
+
+        let decode = match DaliQrCode::new(key, None, None, None, None) {
+            Ok(d) => d,
+            Err(e) => panic!("invalid key {}", e),
+        };
+
+        println!("decode qrcode begin , length : {}...", qrlen);
+        match decode.decode(qrcode as *const u8, qrlen, offset as i32) {
+            Ok(d) => {
+                let qrdata = env.get_map(result).expect("invalid qrdata map");
+                qrdata
+                    .put(
+                        *env.new_string("cardno").unwrap(),
+                        *env.new_string(d.cardno).unwrap(),
+                    )
+                    .unwrap();
+                qrdata
+                    .put(
+                        *env.new_string("cardtype").unwrap(),
+                        *env.new_string(d.cardtype).unwrap(),
+                    )
+                    .unwrap();
+                qrdata
+                    .put(
+                        *env.new_string("uid").unwrap(),
+                        *env.new_string(d.uid).unwrap(),
+                    )
+                    .unwrap();
+                return JNI_TRUE;
+            }
+            Err(e) => {
+                println!("Error {:?}", e);
+                return JNI_FALSE;
+            },
+        };
+    }
+}
diff --git a/java/build.gradle b/java/build.gradle
new file mode 100644
index 0000000..8d5987f
--- /dev/null
+++ b/java/build.gradle
@@ -0,0 +1,20 @@
+plugins {
+    id 'java'
+    id 'application'
+}
+
+
+version = '1.0.0'
+
+repositories {
+    mavenCentral()
+    jcenter()
+}
+
+dependencies {
+   implementation 'commons-codec:commons-codec:1.15' 
+}
+
+application {
+    mainClass = 'com.supwisdom.dlsmk.DLSMK'
+}
diff --git a/java/gradle/wrapper/gradle-wrapper.jar b/java/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..e708b1c
--- /dev/null
+++ b/java/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/java/gradle/wrapper/gradle-wrapper.properties b/java/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..14e30f7
--- /dev/null
+++ b/java/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/java/gradlew b/java/gradlew
new file mode 100755
index 0000000..4f906e0
--- /dev/null
+++ b/java/gradlew
@@ -0,0 +1,185 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+    echo "$*"
+}
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=`expr $i + 1`
+    done
+    case $i in
+        0) set -- ;;
+        1) set -- "$args0" ;;
+        2) set -- "$args0" "$args1" ;;
+        3) set -- "$args0" "$args1" "$args2" ;;
+        4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Escape application args
+save () {
+    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+    echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/java/gradlew.bat b/java/gradlew.bat
new file mode 100644
index 0000000..107acd3
--- /dev/null
+++ b/java/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem      https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/java/setting.gradle b/java/setting.gradle
new file mode 100644
index 0000000..001f5f3
--- /dev/null
+++ b/java/setting.gradle
@@ -0,0 +1 @@
+rootProject.name = 'dlsmk'
diff --git a/java/src/main/java/com/supwisdom/dlsmk/DLSMK.java b/java/src/main/java/com/supwisdom/dlsmk/DLSMK.java
new file mode 100644
index 0000000..6150741
--- /dev/null
+++ b/java/src/main/java/com/supwisdom/dlsmk/DLSMK.java
@@ -0,0 +1,44 @@
+package com.supwisdom.dlsmk;
+
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.commons.codec.binary.Base64;
+
+public class DLSMK {
+    static byte[] decodeHex(String hex) {
+        assert hex.length() % 2 == 0;
+        byte[] result = new byte[hex.length() / 2];
+        for (int i = 0; i < hex.length(); i += 2) {
+            int t = Integer.parseInt(hex.substring(i, i + 2), 16);
+            result[i / 2] = (byte) (((byte) t) & 0xFF);
+        }
+        return result;
+    }
+
+    static String encodeHex(byte[] data) {
+        StringBuffer sb = new StringBuffer();
+        for(int i = 0;i < data.length; i++) {
+            sb.append(String.format("%02x", ((int)data[i]) & 0xff));
+        }
+        return sb.toString();
+    }
+
+    public static void main(String[] args) {
+        System.setProperty("java.library.path" , ".");
+        String key = encodeHex(Base64.decodeBase64("Vbb1syh8U1+CdLmTVGdtDiVvKBQ81n4GmgBEO/ohSbU="));
+        String iv = "55b6f5b3287c535f8274b99354676d0e";
+
+        String qrcode = "6lHyFX_vg5U2hymn8OsdNUD7dT0-sCmEQkKrm9cnzHlku6-FYxuL6nP5YR2Fve8Sfj-Asd-3dfQUkaiqqbfQWO8B_811B3uhHmGm9IjlpLicz_c1H1_ORb9tJl-IhMKu";
+
+
+        System.out.format("Key is %s", key);
+        System.out.println();
+        Map<Object, Object> result = new HashMap();
+        if (DLSMKQrCode.decode(key, qrcode, 0L, result)) {
+            System.out.println("Decode OK");
+        } else {
+            System.out.println("Decode failed");
+        }
+
+    }
+}
diff --git a/java/src/main/java/com/supwisdom/dlsmk/DLSMKQrCode.java b/java/src/main/java/com/supwisdom/dlsmk/DLSMKQrCode.java
new file mode 100644
index 0000000..c83a4a0
--- /dev/null
+++ b/java/src/main/java/com/supwisdom/dlsmk/DLSMKQrCode.java
@@ -0,0 +1,10 @@
+package com.supwisdom.dlsmk;
+
+import java.util.Map;
+
+public class DLSMKQrCode {
+    static {
+        System.loadLibrary("dlsmk");
+    }
+    public static native boolean decode(String keyHex,String qrcode, Long offset, Map<Object, Object> result);
+}