org.bouncycastle.crypto.parsers.XIESPublicKeyParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-debug-jdk15to18 Show documentation
Show all versions of bcprov-debug-jdk15to18 Show documentation
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.5 to JDK 1.8.
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