欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

DESUitls

程序员文章站 2022-04-19 15:05:26
public class test {public static void main(String[] args) {String text = MD5Uitls.encode("https://api.codoon.com/api/get_bind_accounts"+ "^0^"+ "293921e58712a2b287135d67ad91aec9"+ "^"+ "1480391165");System.out.println("====......

 

public class test {

	public static void main(String[] args) {
		String text = MD5Uitls.encode("https://api.codoon.com/api/get_bind_accounts"
				+ "^0^"
				+ "293921e58712a2b287135d67ad91aec9"
				+ "^"
				+ "1480391165");
		System.out.println("================="+text);
		try {
			text = DESUitls.encode(text+"^"
					+ "1480391165");
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("================="+text);
	}
}

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;

import android.util.Base64;


public class DESUitls
{
	public static final String ALGORITHM_DES = "DES/CBC/PKCS5Padding";
	public static final String DES_KEY = "codoon20";
	public static final String INI_VECTOR = "codoon20";

	//	public static byte[] decode(String paramString, byte[] paramArrayOfByte)
	//			throws Exception
	//	{
	//		try
	//		{
	//			new SecureRandom();
	//			paramString = new DESKeySpec(paramString.getBytes());
	//			paramString = SecretKeyFactory.getInstance("DES").generateSecret(paramString);
	//			Cipher localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
	//			localCipher.init(2, paramString, new IvParameterSpec("codoon20".getBytes()));
	//			paramString = localCipher.doFinal(paramArrayOfByte);
	//			return paramString;
	//		}
	//		catch (Exception paramString)
	//		{
	//			throw new Exception(paramString);
	//		}
	//	}

	public static String encode(String paramString)
			throws Exception
	{
		return encode("codoon20", paramString.getBytes());
	}

	public static String encode(String paramString1, String paramString2)
			throws Exception
	{
		return encode(paramString1, paramString2.getBytes());
	}

	public static String encode(String paramString, byte[] paramArrayOfByte)
			throws Exception
	{
		try
		{
			DESKeySpec paramString1 = new DESKeySpec(paramString.getBytes());
			SecretKey paramString2 = SecretKeyFactory.getInstance("DES").generateSecret(paramString1);
			Cipher localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
			localCipher.init(1, paramString2, new IvParameterSpec("codoon20".getBytes()));
			byte[] paramString3 = localCipher.doFinal(paramArrayOfByte);
			
			String paramString4 = Base64.encodeToString(paramString3,  paramString3.length);
			return paramString4;
		}
		catch (Exception e)
		{
			throw new Exception(e);
		}
	}
}

 

本文地址:https://blog.csdn.net/qq_21051503/article/details/107286367