ciphertool.java

来自「这是一个轻便的j2ee的web应用框架,是一个在多个项目中运用的实际框架,采用s」· Java 代码 · 共 41 行

JAVA
41
字号
/*
 * Created on 2004-5-11
 *
 */
package com.esimple.service.crypto.cipher;

import com.sun.crypto.provider.SunJCE;
import java.security.Security;
/**
 * @author steven
 *
 */
public class CipherTool {
	static {
		Security.addProvider(new SunJCE());
	}

	public static  String encrypt(String algorithm, String str) throws Exception {
		String result = null;
		Encdec ed = EncdecFactory.getEncdec(algorithm);
		if( ed== null ) throw new Exception("algorithm not support");
		
		result = ed.encrypt(str);
		
		if (result == null)
			throw new Exception("Encrypt string error.");
		else
			return result;
	}

	public static String decrypt(String algorithm,String str) throws Exception {
		String result = null;
		Encdec ed = EncdecFactory.getEncdec(algorithm);
		result = ed.decrypt (str);
		if (result == null)
			throw new Exception("Decrypt string error.");
		else
			return result;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?