All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jeesuite.security.util.SecurityCryptUtils Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.jeesuite.security.util;

import java.nio.charset.StandardCharsets;

import com.jeesuite.common.crypt.Base64;
import com.jeesuite.common.crypt.DES;
import com.jeesuite.common.util.DigestUtils;
import com.jeesuite.common.util.ResourceUtils;

public class SecurityCryptUtils {

	private static String cryptKey;
	
	static{
		String base = ResourceUtils.getProperty("auth.crypt.key",SecurityCryptUtils.class.getName());
		cryptKey = base.substring(0, 2) + DigestUtils.md5Short(base);
	}
	
	public static String getCryptKey() {
		return cryptKey;
	}

	public static String encrypt(String data) {
		 String encode = DES.encrypt(cryptKey, data);
		 byte[] bytes = Base64.encodeToByte(encode.getBytes(StandardCharsets.UTF_8), false);
		 return new String(bytes, StandardCharsets.UTF_8);
	}
	
	public static String decrypt(String data) {
		 byte[] bytes = Base64.decode(data);
		 data = new String(bytes, StandardCharsets.UTF_8);
		 return DES.decrypt(cryptKey, data);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy