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

org.sklsft.commons.crypto.encoding.BasicObjectEncoder Maven / Gradle / Ivy

There is a newer version: 5.0.0-M1
Show newest version
package org.sklsft.commons.crypto.encoding;

import org.sklsft.commons.crypto.exception.CryptingException;
import org.sklsft.commons.text.serialization.Serializer;

public class BasicObjectEncoder implements ObjectEncoder {
	
	private Serializer serializer;
	private StringEncoder encoder;

	
	public BasicObjectEncoder(Serializer serializer, StringEncoder encoder) {
		super();
		this.serializer = serializer;
		this.encoder = encoder;
	}

	@Override
	public String encode(Object object) {
		try {
			return encoder.encode(serializer.serialize(object));
		} catch (Exception e) {
			throw new CryptingException("Failed to encode " + object.toString(), e);
		}
	}
	
	@Override
	public  T decode(String cryptedText, Class targetClass) {
		String serializing = encoder.decode(cryptedText);
		
		try {
			return serializer.deserialize(serializing, targetClass);
		} catch (Exception e) {
			throw new CryptingException("Failed to decode " + cryptedText, e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy