127 lines
5.4 KiB
Java
127 lines
5.4 KiB
Java
|
package org.bouncycastle.jce.provider;
|
||
|
|
||
|
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.ASN1Encoding;
|
||
|
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.PKCS12BagAttributeCarrierImpl;
|
||
|
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class JDKDSAPrivateKey implements DSAPrivateKey, PKCS12BagAttributeCarrier {
|
||
|
private static final long serialVersionUID = -4677259546958385734L;
|
||
|
private PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
||
|
DSAParams dsaSpec;
|
||
|
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() {
|
||
|
try {
|
||
|
return new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(this.dsaSpec.getP(), this.dsaSpec.getQ(), this.dsaSpec.getG())), new ASN1Integer(getX())).getEncoded(ASN1Encoding.DER);
|
||
|
} catch (IOException unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@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.writeObject(this.x);
|
||
|
objectOutputStream.writeObject(this.dsaSpec.getP());
|
||
|
objectOutputStream.writeObject(this.dsaSpec.getQ());
|
||
|
objectOutputStream.writeObject(this.dsaSpec.getG());
|
||
|
this.attrCarrier.writeObject(objectOutputStream);
|
||
|
}
|
||
|
|
||
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||
|
this.x = (BigInteger) objectInputStream.readObject();
|
||
|
this.dsaSpec = new DSAParameterSpec((BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject());
|
||
|
PKCS12BagAttributeCarrierImpl pKCS12BagAttributeCarrierImpl = new PKCS12BagAttributeCarrierImpl();
|
||
|
this.attrCarrier = pKCS12BagAttributeCarrierImpl;
|
||
|
pKCS12BagAttributeCarrierImpl.readObject(objectInputStream);
|
||
|
}
|
||
|
|
||
|
JDKDSAPrivateKey(DSAPrivateKeyParameters dSAPrivateKeyParameters) {
|
||
|
this.x = dSAPrivateKeyParameters.getX();
|
||
|
this.dsaSpec = new DSAParameterSpec(dSAPrivateKeyParameters.getParameters().getP(), dSAPrivateKeyParameters.getParameters().getQ(), dSAPrivateKeyParameters.getParameters().getG());
|
||
|
}
|
||
|
|
||
|
JDKDSAPrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException {
|
||
|
DSAParameter dSAParameter = DSAParameter.getInstance(privateKeyInfo.getPrivateKeyAlgorithm().getParameters());
|
||
|
this.x = ASN1Integer.getInstance(privateKeyInfo.parsePrivateKey()).getValue();
|
||
|
this.dsaSpec = new DSAParameterSpec(dSAParameter.getP(), dSAParameter.getQ(), dSAParameter.getG());
|
||
|
}
|
||
|
|
||
|
JDKDSAPrivateKey(DSAPrivateKeySpec dSAPrivateKeySpec) {
|
||
|
this.x = dSAPrivateKeySpec.getX();
|
||
|
this.dsaSpec = new DSAParameterSpec(dSAPrivateKeySpec.getP(), dSAPrivateKeySpec.getQ(), dSAPrivateKeySpec.getG());
|
||
|
}
|
||
|
|
||
|
JDKDSAPrivateKey(DSAPrivateKey dSAPrivateKey) {
|
||
|
this.x = dSAPrivateKey.getX();
|
||
|
this.dsaSpec = dSAPrivateKey.getParams();
|
||
|
}
|
||
|
|
||
|
protected JDKDSAPrivateKey() {
|
||
|
}
|
||
|
}
|