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

org.bouncycastle.crypto.parsers.XIESPublicKeyParser Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.

There is a newer version: 1.79
Show newest version
package org.bouncycastle.crypto.parsers;

import java.io.IOException;
import java.io.InputStream;

import org.bouncycastle.crypto.KeyParser;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.X25519PublicKeyParameters;
import org.bouncycastle.crypto.params.X448PublicKeyParameters;
import org.bouncycastle.util.io.Streams;

public class XIESPublicKeyParser
    implements KeyParser
{
    private final boolean isX25519;

    public XIESPublicKeyParser(boolean isX25519)
    {
        this.isX25519 = isX25519;
    }

    public AsymmetricKeyParameter readKey(InputStream stream)
        throws IOException
    {
        int size = isX25519 ? 32 : 56;
        byte[] V = new byte[size];
        
        Streams.readFully(stream, V, 0, V.length);

        // cast due to JVM compatibility
        return isX25519 ? (AsymmetricKeyParameter)new X25519PublicKeyParameters(V, 0) : (AsymmetricKeyParameter)new X448PublicKeyParameters(V, 0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy