《数据通信源代码(牧云水务数据信息传输管理系统)(45页).docx》由会员分享,可在线阅读,更多相关《数据通信源代码(牧云水务数据信息传输管理系统)(45页).docx(45页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-数据通信源代码(牧云水务数据信息传输管理系统)-第 45 页package com.movingdt.interceptor;import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target; * api不需要验证登录 * author shareTarget( Elem
2、entType.METHOD, ElementType.TYPE )Retention(RetentionPolicy.RUNTIME)Documentedpublic interface AnonApi package com.movingdt.util;public class ApiResult public static final String CODE_FAIL = -1;public static final String CODE_SUCCESS = 1;public String message;public String code;public Object data;pu
3、blic ApiResult() this(success, ApiResult.CODE_SUCCESS);public ApiResult(String message, String code) this.message = message;this.code = code;public ApiResult(String message, String code,Object data) this.message = message;this.code = code;this.data = data;public String getMessage() return this.messa
4、ge;public void setMessage(String message) this.message = message;public String getCode() return this.code;public void setCode(String code) this.code = code;public Object getData() return data;public void setData(Object data) this.data = data;package com.movingdt.util;import java.io.UnsupportedEncodi
5、ngException;import java.math.BigInteger; * Created with IntelliJ IDEA. User: noah Date: 8/2/13 Time: 10:36 AM To change * this template use File | Settings | File Templates.public class Base58 public static final char ALPHABET = 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz.toCharArray(
6、);private static final int INDEXES = new int128;static for (int i = 0; i INDEXES.length; i+) INDEXESi = -1;for (int i = 0; i ALPHABET.length; i+) INDEXESALPHABETi = i; * Encodes the given bytes in base58. No checksum is appended.public static String encode(byte input) if (input.length = 0) return ;i
7、nput = copyOfRange(input, 0, input.length);/ Count leading zeroes.int zeroCount = 0;while (zeroCount input.length & inputzeroCount = 0) +zeroCount;/ The actual encoding.byte temp = new byteinput.length * 2;int j = temp.length;int startAt = zeroCount;while (startAt input.length) byte mod = divmod58(i
8、nput, startAt);if (inputstartAt = 0) +startAt;temp-j = (byte) ALPHABETmod;/ Strip extra 1 if there are some after decoding.while (j = 0) temp-j = (byte) ALPHABET0;byte output = copyOfRange(temp, j, temp.length);try return new String(output, US-ASCII); catch (UnsupportedEncodingException e) throw new
9、 RuntimeException(e); / Cannot happen.public static byte decode(String input) throws IllegalArgumentException if (input.length() = 0) return new byte0;byte input58 = new byteinput.length();/ Transform the String to a base58 byte sequencefor (int i = 0; i = 0 & c 128) digit58 = INDEXESc;if (digit58 0
10、) throw new IllegalArgumentException(Illegal character + c + at + i);input58i = (byte) digit58;/ Count leading zeroesint zeroCount = 0;while (zeroCount input58.length & input58zeroCount = 0) +zeroCount;/ The encodingbyte temp = new byteinput.length();int j = temp.length;int startAt = zeroCount;while
11、 (startAt input58.length) byte mod = divmod256(input58, startAt);if (input58startAt = 0) +startAt;temp-j = mod;/ Do no add extra leading zeroes, move j to first non null byte.while (j number / 58, returns number % 58private static byte divmod58(byte number, int startAt) int remainder = 0;for (int i
12、= startAt; i number / 256, returns number % 256private static byte divmod256(byte number58, int startAt) int remainder = 0;for (int i = startAt; i lastTime) lastTime = lastModified;try reload(f); finally if (lock1.getCount() 0)lock1.countDown();public void reload(File f) public void waitFirstRun() t
13、hrows InterruptedException lock1.await();package com.movingdt.util;public class Constant public static String CookieNameICTK = ICTK;public static String COOKIE_PATH = /;public static String VERSION = v1;public static int COOKIE_ICTK_MAXAGE = 60 * 60 * 24 * 90; / 90天单位s 0删除public static final String
14、LOGIN_USER_KEY = LoginUser;public static final String LOGIN = /login; / 登录地址package com.movingdt.util;import java.security.GeneralSecurityException;import java.security.SecureRandom;import javax.crypto.Cipher;import javax.crypto.KeyGenerator;import javax.crypto.SecretKey;import javax.crypto.spec.IvP
15、arameterSpec;import javax.crypto.spec.SecretKeySpec;import mons.codec.binary.Base64;public class CryptUtil private static final String AES = AES;private static final String AES_CBC = AES/CBC/PKCS5Padding;private static final int DEFAULT_AES_KEYSIZE = 128;private static final int DEFAULT_IVSIZE = 16;
16、public static void main(String args) throws Exception byte key128Base64 = Base64.decodeBase64(Ege8HbbmsSz0RlKR/Ynjsw=);byte enc = encryptAES(你123b.getBytes(), key128Base64);byte src = decryptAES(enc, key128Base64);System.out.println(Base64.encodeBase64String(enc);System.out.println(new String(src);p
17、ublic static byte ivBase64 = Base64.decodeBase64(ac80PYOAkewM6OrceBSc7g=);public static byte key128Base64 = Base64.decodeBase64(Ege8HbbmsSz0RlKR/Ynjsw=);public static class AESKeyGen private static SecureRandom random = new SecureRandom();public static void main(String args) System.out.println(ivBas
18、e64=Base64.decodeBase64( + new String(Base64.encodeBase64(generateIV()System.out.println(key128Base64=Base64.decodeBase64(+ new String(Base64.encodeBase64(generateAesKey() + ););public static byte generateAesKey() return generateAesKey(DEFAULT_AES_KEYSIZE);public static byte generateAesKey(int keysi
19、ze) try KeyGenerator keyGenerator = KeyGenerator.getInstance(AES);keyGenerator.init(keysize);SecretKey secretKey = keyGenerator.generateKey();return secretKey.getEncoded(); catch (GeneralSecurityException e) throw new RuntimeException(e);public static byte generateIV() byte bytes = new byteDEFAULT_I
20、VSIZE;random.nextBytes(bytes);return bytes;/ - AES funciton -/public static byte encryptAES(byte input, byte key) return aes(input, key, Cipher.ENCRYPT_MODE);public static byte encryptAES(byte input, byte key, byte iv) return aes(input, key, iv, Cipher.ENCRYPT_MODE);public static byte decryptAES(byt
21、e input, byte key) return aes(input, key, Cipher.DECRYPT_MODE);public static String decryptAESString(byte input, byte key) byte decryptResult = aes(input, key, Cipher.DECRYPT_MODE);return new String(decryptResult);public static String decryptAES(byte input, byte key, byte iv) byte decryptResult = ae
22、s(input, key, iv, Cipher.DECRYPT_MODE);return new String(decryptResult);public static byte aes(byte input, byte key, int mode) try SecretKey secretKey = new SecretKeySpec(key, AES);Cipher cipher = Cipher.getInstance(AES);cipher.init(mode, secretKey);return cipher.doFinal(input); catch (GeneralSecuri
23、tyException e) throw new RuntimeException(e);public static byte aes(byte input, byte key, byte iv, int mode) try SecretKey secretKey = new SecretKeySpec(key, AES);IvParameterSpec ivSpec = new IvParameterSpec(iv);Cipher cipher = Cipher.getInstance(AES_CBC);cipher.init(mode, secretKey, ivSpec);return
24、cipher.doFinal(input); catch (GeneralSecurityException e) throw new RuntimeException(e);package com.movingdt.entity;import java.util.Date;public class DeviceHistoryInfo private Integer id;private Integer deviceId;private String deviceSymbol;private String deviceName;private Integer groupId;private S
25、tring deviceGroupName;private String deviceGroupDesc;private String deviceValue;private String qualities;private Date createTime;private Date updateTime;public Integer getId() return id;public void setId(Integer id) this.id = id;public Integer getDeviceId() return deviceId;public void setDeviceId(In
26、teger deviceId) this.deviceId = deviceId;public String getDeviceSymbol() return deviceSymbol;public void setDeviceSymbol(String deviceSymbol) this.deviceSymbol = deviceSymbol = null ? null : deviceSymbol.trim();public String getDeviceName() return deviceName;public void setDeviceName(String deviceNa
27、me) this.deviceName = deviceName = null ? null : deviceName.trim();public Integer getGroupId() return groupId;public void setGroupId(Integer groupId) this.groupId = groupId;public String getDeviceGroupName() return deviceGroupName;public void setDeviceGroupName(String deviceGroupName) this.deviceGro
28、upName = deviceGroupName = null ? null : deviceGroupName.trim();public String getDeviceGroupDesc() return deviceGroupDesc;public void setDeviceGroupDesc(String deviceGroupDesc) this.deviceGroupDesc = deviceGroupDesc = null ? null : deviceGroupDesc.trim();public String getDeviceValue() return deviceV
29、alue;public void setDeviceValue(String deviceValue) this.deviceValue = deviceValue = null ? null : deviceValue.trim();public String getQualities() return qualities;public void setQualities(String qualities) this.qualities = qualities;public Date getCreateTime() return createTime;public void setCreat
30、eTime(Date createTime) this.createTime = createTime;public Date getUpdateTime() return updateTime;public void setUpdateTime(Date updateTime) this.updateTime = updateTime;Overridepublic String toString() return DeviceHistoryInfo id= + id + , deviceId= + deviceId + , deviceSymbol= + deviceSymbol+ , de
31、viceName= + deviceName + , groupId= + groupId + , deviceGroupName= + deviceGroupName+ , deviceGroupDesc= + deviceGroupDesc + , deviceValue= + deviceValue + , createTime=+ createTime + , updateTime= + updateTime + ;id, device_id, device_symbol, device_name, group_id,device_group_name,device_group_desc,device_value, qualities,create_time, update_timeselectfrom device_history_infowhere id = #id,jdbcType=INTEGERdelete fromdevice_history_infowhere id = #id,jdbcType=INTEGERinsert intodevice_history_info (id, device_id, device_symbol,device_name,group_id, device_g
限制150内