手机号加密程序

package test.pingan.isc.sdk.callisc;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import com.pingan.isc.sdk.bean.BaseResponse;
import com.pingan.isc.sdk.bean.CipherResponse;
import com.pingan.isc.sdk.bean.DecipherResponse;
import com.pingan.isc.sdk.client.ISCClient;

/**
 * 可获取返回的结果码数据
 * @author CHENXIANG287
 *
 */
public class CommonMain {
	private static String sysID = "SIS-OAS";
	private static String userID = "RZRQBUS";
	private static String fatURL = "http://10.25.163.144:80/isc-openapi";
	
	//http请求相关参数
	private static int connTO = 3000;		//连接超时时间
	private static int soTO = 3000;			//io超时时间
	private static boolean keepAlive = true;//是否保持长连接
	private static ISCClient client = null;
	
	//输入加密串
	private static String cipherTelStr(){
		Scanner scan = new Scanner(System.in);
		String cipherStr = scan.nextLine();
		return cipherStr;
	}
	
	public static void main(String[] args) {
		//初始化客户端
		client = new ISCClient();
		//基本信息
		client.initClient(sysID,fatURL);
		//网络配置,可选
		client.initHttpConf(connTO, soTO, keepAlive);
		//--------------------------------- 测试 START ---------------------------------//
		System.out.println("1.加密; 2.解密。退出请输q。请输入对应的序号:");
		boolean flag = true;
		while(flag){
			String inputContent = cipherTelStr();
			if(inputContent.equals("1")){
				//======== 加密 ==========//
				System.out.println("请输入需要加密的手机号码:");
				String telNo = cipherTelStr();
				cipherTel(telNo);
				Map<String,String> plainMap = new HashMap<String,String>();
				plainMap.put("001", telNo);
				Map<String,String> retMap = new HashMap<String,String>();
				batchCipherTel(plainMap,retMap);
			}else if(inputContent.equals("2")){
				System.out.println("请输入需要解密的密码串:");
				String cipherNo = cipherTelStr();
				decipherTel(cipherNo);
			}else{
				if(inputContent.equals("q") || inputContent.equals("Q")){
					flag = false;
				}else{
					System.out.println("请重新输入正确的序号!");
				}
			}
		}
		

		
		//======== 解密 ==========//
//		"1351164702006090199983723";
/*		System.out.println("请输入需要解密的加密串:");
		String cipherNo = cipherTelStr();
		decipherTel(cipherNo);*/
		//--------------------------------- 测试 END ---------------------------------//
	}
	
	/*
	 * 加密
	 */
	public static void cipherTel(String telNo){
		CipherResponse cipherResp = client.cipherTelNO(telNo,userID);
		System.out.println("加密后的密码串 : " + cipherResp.getCipherText());
	}
	
	/*
	 * 批量加密
	 */
	public static void batchCipherTel(Map<String,String> plainMap,Map<String,String> retMap){
		BaseResponse resp = client.batchCipherTel(plainMap, retMap,userID);
//		System.out.println("[batchCipherTel]httpCode : " + resp.getHttpCode() + " | retCode : " + resp.getRetCode());
	}
	
	/*
	 * 解密
	 */
	public static void decipherTel(String cipherNo){
		DecipherResponse resp = client.decipherTelNO(cipherNo, userID);
//		System.out.println("[decipherTel]HttpCode : " + resp.getHttpCode() + " | RetCode : " + resp.getRetCode() + " | RetMsg : " + resp.getRetMsg() + " |解密后原文  : " + resp.getPlainText());
		System.out.println("解密后原文  : " + resp.getPlainText());
	}
	
	/*
	 * 批量解密
	 */
	public static void batchDecipherTel(Map<String,String> cipherMap,Map<String,String> retMap){
		BaseResponse resp = client.batchDecipherTel(cipherMap, retMap, userID);
		System.out.println("[batchCipherTel]httpCode : " + resp.getHttpCode() + " | retCode : " + resp.getRetCode());
	}
	
	/*
	 * 获取掩码
	 */
	public static void gainTelMark(String cipherNo){
		DecipherResponse resp = client.gainDefTelMarkNo(cipherNo, userID);
		System.out.println("[gainTelMark]HttpCode : " + resp.getHttpCode() + " | RetCode : " + resp.getRetCode() + " | RetMsg : " + resp.getRetMsg() + " | PlainText : " + resp.getPlainText());
	}
	
	/*
	 * 批量获取掩码
	 */
	public static void batchGainTelMark(Map<String,String> cipherMap,Map<String,String> retMap){
		BaseResponse resp = client.batchGetDefTelMarkNo(cipherMap, retMap, userID);
		System.out.println("[batchGainTelMark]httpCode : " + resp.getHttpCode() + " | retCode : " + resp.getRetCode());
	}
	
	/*
	 * 获取指定规则掩码
	 */
	public static void gainSpecialTelMark(String cipherNo,int startIndex,int endIndex){
		DecipherResponse resp = client.gainTelMarkNo(cipherNo, startIndex,endIndex,userID);
		System.out.println("[gainSpecialTelMark]HttpCode : " + resp.getHttpCode() + " | RetCode : " + resp.getRetCode() + " | RetMsg : " + resp.getRetMsg() + " | PlainText : " + resp.getPlainText());
		
	}
	
	/*
	 * 批量获取掩码
	 */
	public static void batchGainSpecialTelMark(Map<String,String> cipherMap,Map<String,String> retMap,int startIndex,int endIndex){
		BaseResponse resp = client.batchGetTelMarkNo(cipherMap, retMap,startIndex, endIndex,userID);
		System.out.println("[batchGainSpecialTelMark]httpCode : " + resp.getHttpCode() + " | retCode : " + resp.getRetCode());
	}
}

以下程序是判断加密串是否正确的---了解一下即可

package test.pingan.isc.sdk.chek;

import com.pingan.isc.sdk.utils.EncryptTelUtils;

/**
 * 校验密文
 * 
 * @author CHENXIANG287
 * 
 */
public class CheckCipher {

	public static void main(String[] args) {
		String cipherTelNo = "1521031297512818833010131";
		System.out.println("cipherTelNo : "
				+ EncryptTelUtils.checkEncryptTel(cipherTelNo));

		String cipherTelNo_more = "1521031297512818833010131123213";
		System.out.println("cipherTelNo_more : "
				+ EncryptTelUtils.checkEncryptTel(cipherTelNo_more));

		String cipherTelNo_less = "152103129751281883";
		System.out.println("cipherTelNo_less : "
				+ EncryptTelUtils.checkEncryptTel(cipherTelNo_less));

		String cipherTelNo_invaild = "1521031297abc818833010131";
		System.out.println("cipherTelNo_invaild : "
				+ EncryptTelUtils.checkEncryptTel(cipherTelNo_invaild));
	}

}

猜你喜欢

转载自my.oschina.net/u/3563297/blog/1649570