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

com.safelayer.rap.json.X509CertificateSerializer Maven / Gradle / Ivy

Go to download

The PKI Connector RESTAPI is a library that helps developing new PKI Connectors for TrustedX

The newest version!
package com.safelayer.rap.json;

import java.io.IOException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;

import org.apache.commons.codec.binary.Base64;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class X509CertificateSerializer extends JsonSerializer {

	@Override
	public void serialize(X509Certificate cert, JsonGenerator generator, SerializerProvider serializerProvider)
			throws IOException, JsonProcessingException {
		try {
			generator.writeString(Base64.encodeBase64String(cert.getEncoded()));
		}
		catch (CertificateEncodingException e) {
			throw new JsonException(e);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy