
org.spongycastle.asn1.x509.DSAParameter 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.
package org.spongycastle.asn1.x509;
import java.math.BigInteger;
import java.util.Enumeration;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Integer;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.ASN1TaggedObject;
import org.spongycastle.asn1.DERSequence;
public class DSAParameter
extends ASN1Object
{
ASN1Integer p, q, g;
public static DSAParameter getInstance(
ASN1TaggedObject obj,
boolean explicit)
{
return getInstance(ASN1Sequence.getInstance(obj, explicit));
}
public static DSAParameter getInstance(
Object obj)
{
if (obj instanceof DSAParameter)
{
return (DSAParameter)obj;
}
if(obj != null)
{
return new DSAParameter(ASN1Sequence.getInstance(obj));
}
return null;
}
public DSAParameter(
BigInteger p,
BigInteger q,
BigInteger g)
{
this.p = new ASN1Integer(p);
this.q = new ASN1Integer(q);
this.g = new ASN1Integer(g);
}
private DSAParameter(
ASN1Sequence seq)
{
if (seq.size() != 3)
{
throw new IllegalArgumentException("Bad sequence size: " + seq.size());
}
Enumeration e = seq.getObjects();
p = ASN1Integer.getInstance(e.nextElement());
q = ASN1Integer.getInstance(e.nextElement());
g = ASN1Integer.getInstance(e.nextElement());
}
public BigInteger getP()
{
return p.getPositiveValue();
}
public BigInteger getQ()
{
return q.getPositiveValue();
}
public BigInteger getG()
{
return g.getPositiveValue();
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(p);
v.add(q);
v.add(g);
return new DERSequence(v);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy