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

org.echocat.marquardt.common.serialization.PublicKeyDeserializer Maven / Gradle / Ivy

/*
 * echocat Marquardt Java SDK, Copyright (c) 2015 echocat
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package org.echocat.marquardt.common.serialization;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import org.echocat.marquardt.common.domain.PublicKeyWithMechanism;

import java.io.IOException;
import java.security.PublicKey;

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

public class PublicKeyDeserializer extends JsonDeserializer {
    @Override
    public PublicKey deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
        final ObjectCodec oc = jsonParser.getCodec();
        final JsonNode node = oc.readTree(jsonParser);
        return new PublicKeyWithMechanism(decodeBase64(node.get(PublicKeySerializer.KEY).binaryValue())).toJavaKey();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy