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

com.safelayer.rap.json.X509CertificateDeserializer 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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

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

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

public class X509CertificateDeserializer extends JsonDeserializer {

	@Override
	public X509Certificate deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		try {
			String value = parser.readValueAs(String.class);
			byte[] certEncoded = Base64.decodeBase64(value);
			InputStream in = new ByteArrayInputStream(certEncoded);
			CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
			return (X509Certificate) certFactory.generateCertificate(in);
		}
		catch (CertificateException e) {
			throw new JsonException(e);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy