what-the-bank/sources/org/bouncycastle/jcajce/provider/asymmetric/dsa/BCDSAPublicKey.java

133 lines
5.6 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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.DSAPublicKey;
import java.security.spec.DSAParameterSpec;
import java.security.spec.DSAPublicKeySpec;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.DSAParameter;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.crypto.params.DSAPublicKeyParameters;
import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
import org.bouncycastle.util.Strings;
/* loaded from: classes6.dex */
public class BCDSAPublicKey implements DSAPublicKey {
private static final long serialVersionUID = 1752452449903495175L;
private transient DSAParams dsaSpec;
private BigInteger y;
public String toString() {
StringBuffer stringBuffer = new StringBuffer("DSA Public Key");
String lineSeparator = Strings.lineSeparator();
stringBuffer.append(lineSeparator);
stringBuffer.append(" y: ").append(getY().toString(16)).append(lineSeparator);
return stringBuffer.toString();
}
public int hashCode() {
return ((getY().hashCode() ^ getParams().getG().hashCode()) ^ getParams().getP().hashCode()) ^ getParams().getQ().hashCode();
}
@Override // java.security.interfaces.DSAPublicKey
public BigInteger getY() {
return this.y;
}
@Override // java.security.interfaces.DSAKey
public DSAParams getParams() {
return this.dsaSpec;
}
@Override // java.security.Key
public String getFormat() {
return "X.509";
}
@Override // java.security.Key
public byte[] getEncoded() {
AlgorithmIdentifier algorithmIdentifier;
ASN1Integer aSN1Integer;
if (this.dsaSpec == null) {
algorithmIdentifier = new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa);
aSN1Integer = new ASN1Integer(this.y);
} else {
algorithmIdentifier = new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(this.dsaSpec.getP(), this.dsaSpec.getQ(), this.dsaSpec.getG()).toASN1Primitive());
aSN1Integer = new ASN1Integer(this.y);
}
return KeyUtil.getEncodedSubjectPublicKeyInfo(algorithmIdentifier, aSN1Integer);
}
@Override // java.security.Key
public String getAlgorithm() {
return "DSA";
}
public boolean equals(Object obj) {
if (!(obj instanceof DSAPublicKey)) {
return false;
}
DSAPublicKey dSAPublicKey = (DSAPublicKey) obj;
return getY().equals(dSAPublicKey.getY()) && getParams().getG().equals(dSAPublicKey.getParams().getG()) && getParams().getP().equals(dSAPublicKey.getParams().getP()) && getParams().getQ().equals(dSAPublicKey.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());
}
private boolean isNotNull(ASN1Encodable aSN1Encodable) {
return (aSN1Encodable == null || DERNull.INSTANCE.equals(aSN1Encodable.toASN1Primitive())) ? false : true;
}
/* JADX INFO: Access modifiers changed from: package-private */
public BCDSAPublicKey(DSAPublicKeyParameters dSAPublicKeyParameters) {
this.y = dSAPublicKeyParameters.getY();
this.dsaSpec = new DSAParameterSpec(dSAPublicKeyParameters.getParameters().getP(), dSAPublicKeyParameters.getParameters().getQ(), dSAPublicKeyParameters.getParameters().getG());
}
public BCDSAPublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo) {
try {
this.y = ((ASN1Integer) subjectPublicKeyInfo.parsePublicKey()).getValue();
if (isNotNull(subjectPublicKeyInfo.getAlgorithm().getParameters())) {
DSAParameter dSAParameter = DSAParameter.getInstance(subjectPublicKeyInfo.getAlgorithm().getParameters());
this.dsaSpec = new DSAParameterSpec(dSAParameter.getP(), dSAParameter.getQ(), dSAParameter.getG());
}
} catch (IOException unused) {
throw new IllegalArgumentException("invalid info structure in DSA public key");
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public BCDSAPublicKey(DSAPublicKeySpec dSAPublicKeySpec) {
this.y = dSAPublicKeySpec.getY();
this.dsaSpec = new DSAParameterSpec(dSAPublicKeySpec.getP(), dSAPublicKeySpec.getQ(), dSAPublicKeySpec.getG());
}
/* JADX INFO: Access modifiers changed from: package-private */
public BCDSAPublicKey(DSAPublicKey dSAPublicKey) {
this.y = dSAPublicKey.getY();
this.dsaSpec = dSAPublicKey.getParams();
}
BCDSAPublicKey(BigInteger bigInteger, DSAParameterSpec dSAParameterSpec) {
this.y = bigInteger;
this.dsaSpec = dSAParameterSpec;
}
}