com.fitbur.bouncycastle.crypto.parsers.ECIESPublicKeyParser Maven / Gradle / Ivy
package com.fitbur.bouncycastle.crypto.parsers;
import java.io.IOException;
import java.io.InputStream;
import com.fitbur.bouncycastle.crypto.KeyParser;
import com.fitbur.bouncycastle.crypto.params.AsymmetricKeyParameter;
import com.fitbur.bouncycastle.crypto.params.ECDomainParameters;
import com.fitbur.bouncycastle.crypto.params.ECPublicKeyParameters;
public class ECIESPublicKeyParser
implements KeyParser
{
private ECDomainParameters ecParams;
public ECIESPublicKeyParser(ECDomainParameters ecParams)
{
this.ecParams = ecParams;
}
public AsymmetricKeyParameter readKey(InputStream stream)
throws IOException
{
byte[] V;
int first = stream.read();
// Decode the public ephemeral key
switch (first)
{
case 0x00: // infinity
throw new IOException("Sender's public key invalid.");
case 0x02: // com.fitburpressed
case 0x03: // Byte length calculated as in ECPoint.getEncoded();
V = new byte[1 + (ecParams.getCurve().getFieldSize()+7)/8];
break;
case 0x04: // uncompressed or
case 0x06: // hybrid
case 0x07: // Byte length calculated as in ECPoint.getEncoded();
V = new byte[1 + 2*((ecParams.getCurve().getFieldSize()+7)/8)];
break;
com.fitburfault:
throw new IOException("Sender's public key has invalid point encoding 0x" + Integer.toString(first, 16));
}
V[0] = (byte)first;
stream.read(V, 1, V.length - 1);
return new ECPublicKeyParameters(ecParams.getCurve().com.fitburcodePoint(V), ecParams);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy