Authored by skinny.wu

DNS域名解析 模块

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>monitor-service-parent</artifactId>
<groupId>monitor-service</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>monitor-service-other</artifactId>
<dependencies>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-common</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.monitor.other.dns;
import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import sun.misc.BASE64Decoder;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.*;
/**
* Created by yoho on 2016/7/29.
*/
public class AESTest {
public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException, InvalidAlgorithmParameterException, NoSuchProviderException {
String password = "yoho9646YOHO9646";
byte[] digest = password.getBytes("UTF-8");
// 初始化
Security.addProvider(new BouncyCastleProvider());
Key aesKey = new SecretKeySpec(digest, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
IvParameterSpec iv = new IvParameterSpec("YOHO9646yoho9646".getBytes("UTF-8"));
//
cipher.init(Cipher.ENCRYPT_MODE, aesKey, iv);
byte[] bytes2 = cipher.doFinal("uid=1000&domain=api.yoho.cn".getBytes("utf-8"));
System.out.println(Base64.encodeBase64String(bytes2));
BASE64Decoder decoder = new BASE64Decoder();
byte[] bytes3 = decoder.decodeBuffer("n5+xSdOrP5MyhX37SqOxmzyif3+/GbmuQMCrsKIZwRJ+OED/aYjRA//Cz0/IyxnuUCcD8lxb/iFiReJHldMrxbo3bwzTs/tclhEBSuubqv8qKIrpNTh2W9+ac27djDHeLjifmVL7WgI4VNWvHw6vhQ5Bpli4GohmuIeFx/7pTMT9AKEnDnC8Yg/AJmiHzzhKy9u8t1N5d/vHT+1WhURkbsyQDQ/Due8Ygar4+aCC32xyinrY3nbJYHjfouj6bw0kE4r9ebHkyjyeAmqUFIjycqdaMk6sHJrO7R3TDw4r8yE=");
byte[] bytes = decoder.decodeBuffer(Base64.encodeBase64String(bytes3));
cipher.init(Cipher.DECRYPT_MODE, aesKey, iv);
byte[] bytes1 = cipher.doFinal(bytes);
String decryptMsg = new String(bytes1, "UTF-8");
System.out.println(decryptMsg);
IP ip = JSON.parseObject(decryptMsg, IP.class);
MessageDigest mdInst = MessageDigest.getInstance("MD5");
byte[] digest1 = mdInst.digest(ip.getContent().getBytes("UTF-8"));
String s = Hex.encodeHexString(digest1);
System.out.println(s);
}
private static class IP {
private String md5;
private String content;
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
}
... ...
package com.monitor.other.dns.util;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.util.List;
/**
* Created by yoho on 2016/7/29.
*/
public class AESUtil {
private static final String secretKeyStr = "yoho9646YOHO9646";
private static final String offsetVectorStr = "YOHO9646yoho9646";
private static byte[] secretKeyBytes;
private static byte[] offsetVectorBytes;
private static Logger logger = LoggerFactory.getLogger(AESUtil.class);
private static Cipher cipher;
private static IvParameterSpec ivParameterSpec;
/**
* 获取SerectKey的utf-8编码的字节码
*
* @return
* @throws UnsupportedEncodingException
*/
private static byte[] getSecretKeyBytes() {
if (null == secretKeyBytes) {
try {
secretKeyBytes = secretKeyStr.getBytes("UTF-8");
} catch (UnsupportedEncodingException unsupportedEncodingException) {
logger.error(unsupportedEncodingException.toString());
return null;
}
}
return secretKeyBytes;
}
/**
* 获取偏移向量的utf-8编码的字节码
*
* @return
* @throws UnsupportedEncodingException
*/
private static byte[] getOffsetVectorBytes() {
if (null == offsetVectorBytes) {
try {
offsetVectorBytes = offsetVectorStr.getBytes("UTF-8");
} catch (UnsupportedEncodingException unsupportedEncodingException) {
logger.error(unsupportedEncodingException.toString());
return null;
}
}
return offsetVectorBytes;
}
private static Cipher getCipher() {
if (null == cipher) {
try {
cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
}catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
}
return cipher;
}
// private static IvParameterSpec getIvParameterSpec() {
// if (null == ivParameterSpec) {
// // TODO
//// ivParameterSpec = new IvParameterSpec()
// }
// }
// public static String EncodeACEBase64(String source) {
// Security.addProvider(new BouncyCastleProvider());
//// Key aesKey = new SecretKeySpec(getSerectKeyBytes(), "AES");
//
// return "";
// }
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
</beans>
\ No newline at end of file
... ...
... ... @@ -143,6 +143,7 @@
<module>monitor-service-model</module>
<module>monitor-service-middleware</module>
<module>monitor-service-user</module>
<module>monitor-service-other</module>
</modules>
... ...