![JAR search and dependency download from the Maven repository](/logo.png)
org.spongycastle.asn1.x9.X9ECPoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.asn1.x9;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1OctetString;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.DEROctetString;
import org.spongycastle.math.ec.ECCurve;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.util.Arrays;
/**
* class for describing an ECPoint as a DER object.
*/
public class X9ECPoint
extends ASN1Object
{
private final ASN1OctetString encoding;
private ECCurve c;
private ECPoint p;
public X9ECPoint(
ECPoint p)
{
this(p, false);
}
public X9ECPoint(
ECPoint p,
boolean compressed)
{
this.p = p.normalize();
this.encoding = new DEROctetString(p.getEncoded(compressed));
}
public X9ECPoint(
ECCurve c,
byte[] encoding)
{
this.c = c;
this.encoding = new DEROctetString(Arrays.clone(encoding));
}
public X9ECPoint(
ECCurve c,
ASN1OctetString s)
{
this(c, s.getOctets());
}
public byte[] getPointEncoding()
{
return Arrays.clone(encoding.getOctets());
}
public synchronized ECPoint getPoint()
{
if (p == null)
{
p = c.decodePoint(encoding.getOctets()).normalize();
}
return p;
}
public boolean isPointCompressed()
{
byte[] octets = encoding.getOctets();
return octets != null && octets.length > 0 && (octets[0] == 2 || octets[0] == 3);
}
/**
* Produce an object suitable for an ASN1OutputStream.
*
* ECPoint ::= OCTET STRING
*
*
* Octet string produced using ECPoint.getEncoded().
*/
public ASN1Primitive toASN1Primitive()
{
return encoding;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy