手機號加密程序

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());
	}
}

 

如下程序是判斷加密串是否正確的---瞭解一下便可java

 

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));
	}

}
相關文章
相關標籤/搜索