123 lines
5.4 KiB
Java
123 lines
5.4 KiB
Java
package org.bouncycastle.jcajce.provider.asymmetric.dsa;
|
|
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.math.BigInteger;
|
|
import java.security.interfaces.DSAParams;
|
|
import java.security.interfaces.DSAPrivateKey;
|
|
import java.security.spec.DSAParameterSpec;
|
|
import java.security.spec.DSAPrivateKeySpec;
|
|
import java.util.Enumeration;
|
|
import org.bouncycastle.asn1.ASN1Encodable;
|
|
import org.bouncycastle.asn1.ASN1Integer;
|
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
|
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
|
import org.bouncycastle.asn1.x509.DSAParameter;
|
|
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
|
|
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
|
|
import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
|
|
import org.bouncycastle.jcajce.provider.asymmetric.util.PKCS12BagAttributeCarrierImpl;
|
|
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class BCDSAPrivateKey implements DSAPrivateKey, PKCS12BagAttributeCarrier {
|
|
private static final long serialVersionUID = -4677259546958385734L;
|
|
private transient PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
private transient DSAParams dsaSpec;
|
|
private BigInteger x;
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
|
public void setBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier, ASN1Encodable aSN1Encodable) {
|
|
this.attrCarrier.setBagAttribute(aSN1ObjectIdentifier, aSN1Encodable);
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ((getX().hashCode() ^ getParams().getG().hashCode()) ^ getParams().getP().hashCode()) ^ getParams().getQ().hashCode();
|
|
}
|
|
|
|
@Override // java.security.interfaces.DSAPrivateKey
|
|
public BigInteger getX() {
|
|
return this.x;
|
|
}
|
|
|
|
@Override // java.security.interfaces.DSAKey
|
|
public DSAParams getParams() {
|
|
return this.dsaSpec;
|
|
}
|
|
|
|
@Override // java.security.Key
|
|
public String getFormat() {
|
|
return "PKCS#8";
|
|
}
|
|
|
|
@Override // java.security.Key
|
|
public byte[] getEncoded() {
|
|
return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(this.dsaSpec.getP(), this.dsaSpec.getQ(), this.dsaSpec.getG()).toASN1Primitive()), new ASN1Integer(getX()));
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
|
public Enumeration getBagAttributeKeys() {
|
|
return this.attrCarrier.getBagAttributeKeys();
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
|
public ASN1Encodable getBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier) {
|
|
return this.attrCarrier.getBagAttribute(aSN1ObjectIdentifier);
|
|
}
|
|
|
|
@Override // java.security.Key
|
|
public String getAlgorithm() {
|
|
return "DSA";
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof DSAPrivateKey)) {
|
|
return false;
|
|
}
|
|
DSAPrivateKey dSAPrivateKey = (DSAPrivateKey) obj;
|
|
return getX().equals(dSAPrivateKey.getX()) && getParams().getG().equals(dSAPrivateKey.getParams().getG()) && getParams().getP().equals(dSAPrivateKey.getParams().getP()) && getParams().getQ().equals(dSAPrivateKey.getParams().getQ());
|
|
}
|
|
|
|
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
|
|
objectOutputStream.defaultWriteObject();
|
|
objectOutputStream.writeObject(this.dsaSpec.getP());
|
|
objectOutputStream.writeObject(this.dsaSpec.getQ());
|
|
objectOutputStream.writeObject(this.dsaSpec.getG());
|
|
}
|
|
|
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
objectInputStream.defaultReadObject();
|
|
this.dsaSpec = new DSAParameterSpec((BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject());
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public BCDSAPrivateKey(DSAPrivateKeyParameters dSAPrivateKeyParameters) {
|
|
this.x = dSAPrivateKeyParameters.getX();
|
|
this.dsaSpec = new DSAParameterSpec(dSAPrivateKeyParameters.getParameters().getP(), dSAPrivateKeyParameters.getParameters().getQ(), dSAPrivateKeyParameters.getParameters().getG());
|
|
}
|
|
|
|
public BCDSAPrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException {
|
|
DSAParameter dSAParameter = DSAParameter.getInstance(privateKeyInfo.getPrivateKeyAlgorithm().getParameters());
|
|
this.x = ((ASN1Integer) privateKeyInfo.parsePrivateKey()).getValue();
|
|
this.dsaSpec = new DSAParameterSpec(dSAParameter.getP(), dSAParameter.getQ(), dSAParameter.getG());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public BCDSAPrivateKey(DSAPrivateKeySpec dSAPrivateKeySpec) {
|
|
this.x = dSAPrivateKeySpec.getX();
|
|
this.dsaSpec = new DSAParameterSpec(dSAPrivateKeySpec.getP(), dSAPrivateKeySpec.getQ(), dSAPrivateKeySpec.getG());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public BCDSAPrivateKey(DSAPrivateKey dSAPrivateKey) {
|
|
this.x = dSAPrivateKey.getX();
|
|
this.dsaSpec = dSAPrivateKey.getParams();
|
|
}
|
|
|
|
protected BCDSAPrivateKey() {
|
|
}
|
|
}
|