简单的lisence生成过程_自己用的

只是自己中转一下。有其它类依赖的。

package test.yuan;

import java.util.Random;


/**
 * @author Syy
 *
 */
public class GenerateLisence {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String mac=MacAdressUtil.getMacAddress();
		System.out.println(mac);
		//去除-
		String[] macArray=mac.split("-");
		StringBuffer sb=new StringBuffer();
		for (String s:macArray){
			sb.append(s);
		}
		System.out.println(sb.toString());
		//sb.insert(2, 'a');
		//System.out.println(sb.toString());
		mac=sb.toString();
		//加密mac
		String cipherMac=CipherUtil.generatePassword(mac);
		System.out.println(cipherMac);
		System.out.println(sb.length());
		//制作lisence
		Random random=new Random(System.currentTimeMillis());
		int length=sb.length();
		System.out.println("生成的字符:");
		for(int i=0;i<length;i++){
			char randomChar=(char)(random.nextInt(20)+71);
			int randomIndex=random.nextInt(length+i+1);
			System.out.println(randomChar+","+randomIndex);
			sb.insert(randomIndex, randomChar);
			System.out.println(sb);
		}
		//lisence不加密,得到的是24位无序的字符串,接下来还原lisence得到
		//未加密的mac,再加密后与存储的加密后的mac比较,如果相等则注册成功
		System.out.println(sb.length());
		int index=sb.length();
		for(int i=0;i<index;i++){
			char c=sb.charAt(i);
			System.out.print(c+",");
			if(c>'F'){
				sb.deleteCharAt(i);
				index--;
				i--;
			}
		}
		System.out.println(sb.toString());
		String compMac=CipherUtil.generatePassword(sb.toString());
		System.out.println(compMac);
		if(compMac.equals(cipherMac)){
			System.out.println("相等");
		}else{
			System.out.println("不相等");
		}
	}

}

 

你可能感兴趣的:(生成)