106 lines
3.9 KiB
Java
106 lines
3.9 KiB
Java
package org.bouncycastle.asn1.sec;
|
|
|
|
import java.math.BigInteger;
|
|
import java.util.Enumeration;
|
|
import org.bouncycastle.asn1.ASN1Encodable;
|
|
import org.bouncycastle.asn1.ASN1EncodableVector;
|
|
import org.bouncycastle.asn1.ASN1Integer;
|
|
import org.bouncycastle.asn1.ASN1Object;
|
|
import org.bouncycastle.asn1.ASN1OctetString;
|
|
import org.bouncycastle.asn1.ASN1Primitive;
|
|
import org.bouncycastle.asn1.ASN1Sequence;
|
|
import org.bouncycastle.asn1.ASN1TaggedObject;
|
|
import org.bouncycastle.asn1.DERBitString;
|
|
import org.bouncycastle.asn1.DEROctetString;
|
|
import org.bouncycastle.asn1.DERSequence;
|
|
import org.bouncycastle.asn1.DERTaggedObject;
|
|
import org.bouncycastle.util.BigIntegers;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class ECPrivateKey extends ASN1Object {
|
|
private ASN1Sequence seq;
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable
|
|
public ASN1Primitive toASN1Primitive() {
|
|
return this.seq;
|
|
}
|
|
|
|
public DERBitString getPublicKey() {
|
|
return (DERBitString) getObjectInTag(1);
|
|
}
|
|
|
|
public ASN1Primitive getParameters() {
|
|
return getObjectInTag(0);
|
|
}
|
|
|
|
public BigInteger getKey() {
|
|
return new BigInteger(1, ((ASN1OctetString) this.seq.getObjectAt(1)).getOctets());
|
|
}
|
|
|
|
private ASN1Primitive getObjectInTag(int i) {
|
|
Enumeration objects = this.seq.getObjects();
|
|
while (objects.hasMoreElements()) {
|
|
ASN1Encodable aSN1Encodable = (ASN1Encodable) objects.nextElement();
|
|
if (aSN1Encodable instanceof ASN1TaggedObject) {
|
|
ASN1TaggedObject aSN1TaggedObject = (ASN1TaggedObject) aSN1Encodable;
|
|
if (aSN1TaggedObject.getTagNo() == i) {
|
|
return aSN1TaggedObject.getObject().toASN1Primitive();
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static ECPrivateKey getInstance(Object obj) {
|
|
if (obj instanceof ECPrivateKey) {
|
|
return (ECPrivateKey) obj;
|
|
}
|
|
if (obj != null) {
|
|
return new ECPrivateKey(ASN1Sequence.getInstance(obj));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private ECPrivateKey(ASN1Sequence aSN1Sequence) {
|
|
this.seq = aSN1Sequence;
|
|
}
|
|
|
|
public ECPrivateKey(BigInteger bigInteger, DERBitString dERBitString, ASN1Encodable aSN1Encodable) {
|
|
this(bigInteger.bitLength(), bigInteger, dERBitString, aSN1Encodable);
|
|
}
|
|
|
|
public ECPrivateKey(BigInteger bigInteger, ASN1Encodable aSN1Encodable) {
|
|
this(bigInteger, (DERBitString) null, aSN1Encodable);
|
|
}
|
|
|
|
public ECPrivateKey(BigInteger bigInteger) {
|
|
this(bigInteger.bitLength(), bigInteger);
|
|
}
|
|
|
|
public ECPrivateKey(int i, BigInteger bigInteger, DERBitString dERBitString, ASN1Encodable aSN1Encodable) {
|
|
byte[] asUnsignedByteArray = BigIntegers.asUnsignedByteArray((i + 7) / 8, bigInteger);
|
|
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
|
|
aSN1EncodableVector.add(new ASN1Integer(1L));
|
|
aSN1EncodableVector.add(new DEROctetString(asUnsignedByteArray));
|
|
if (aSN1Encodable != null) {
|
|
aSN1EncodableVector.add(new DERTaggedObject(true, 0, aSN1Encodable));
|
|
}
|
|
if (dERBitString != null) {
|
|
aSN1EncodableVector.add(new DERTaggedObject(true, 1, dERBitString));
|
|
}
|
|
this.seq = new DERSequence(aSN1EncodableVector);
|
|
}
|
|
|
|
public ECPrivateKey(int i, BigInteger bigInteger, ASN1Encodable aSN1Encodable) {
|
|
this(i, bigInteger, null, aSN1Encodable);
|
|
}
|
|
|
|
public ECPrivateKey(int i, BigInteger bigInteger) {
|
|
byte[] asUnsignedByteArray = BigIntegers.asUnsignedByteArray((i + 7) / 8, bigInteger);
|
|
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
|
|
aSN1EncodableVector.add(new ASN1Integer(1L));
|
|
aSN1EncodableVector.add(new DEROctetString(asUnsignedByteArray));
|
|
this.seq = new DERSequence(aSN1EncodableVector);
|
|
}
|
|
}
|