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

org.onetwo.common.encrypt.AbstractEncryptCoder Maven / Gradle / Ivy

There is a newer version: 4.7.2
Show newest version
package org.onetwo.common.encrypt;

import java.security.Key;

import javax.crypto.Cipher;

import org.onetwo.common.exception.BaseException;

abstract public class AbstractEncryptCoder implements EncryptCoder{

	abstract protected String getAlgorithmCipher();
	

	protected byte[] doCipher(Key skeySpec, int opmode, byte[] byteContent){
		//构造密匙
//		SecretKeySpec skeySpec = new SecretKeySpec(key, AES_KEY);
//		SecretKeySpec skeySpec = new SecretKeySpec(skeyEncoded, AES_KEY);
		//密码器
		Cipher aesCipher = null;
		byte[] result = null;
		try{
			aesCipher = Cipher.getInstance(getAlgorithmCipher());
			aesCipher.init(opmode, skeySpec);
			result = aesCipher.doFinal(byteContent);
		}catch (Exception e) {
			throw new BaseException("Cipher error: " + e.getMessage() , e);
		}
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy