what-the-bank/sources/org/bouncycastle/jce/provider/JDKDSAPublicKey.java

125 lines
5.2 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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.DSAPublicKey;
import java.security.spec.DSAParameterSpec;
import java.security.spec.DSAPublicKeySpec;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Encoding;
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.util.Strings;
/* loaded from: classes6.dex */
public class JDKDSAPublicKey implements DSAPublicKey {
private static final long serialVersionUID = 1752452449903495175L;
private 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() {
try {
return this.dsaSpec == null ? new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa), new ASN1Integer(this.y)).getEncoded(ASN1Encoding.DER) : new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(this.dsaSpec.getP(), this.dsaSpec.getQ(), this.dsaSpec.getG())), new ASN1Integer(this.y)).getEncoded(ASN1Encoding.DER);
} catch (IOException unused) {
return null;
}
}
@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.writeObject(this.y);
objectOutputStream.writeObject(this.dsaSpec.getP());
objectOutputStream.writeObject(this.dsaSpec.getQ());
objectOutputStream.writeObject(this.dsaSpec.getG());
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
this.y = (BigInteger) objectInputStream.readObject();
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)) ? false : true;
}
JDKDSAPublicKey(DSAPublicKeyParameters dSAPublicKeyParameters) {
this.y = dSAPublicKeyParameters.getY();
this.dsaSpec = new DSAParameterSpec(dSAPublicKeyParameters.getParameters().getP(), dSAPublicKeyParameters.getParameters().getQ(), dSAPublicKeyParameters.getParameters().getG());
}
JDKDSAPublicKey(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");
}
}
JDKDSAPublicKey(DSAPublicKeySpec dSAPublicKeySpec) {
this.y = dSAPublicKeySpec.getY();
this.dsaSpec = new DSAParameterSpec(dSAPublicKeySpec.getP(), dSAPublicKeySpec.getQ(), dSAPublicKeySpec.getG());
}
JDKDSAPublicKey(DSAPublicKey dSAPublicKey) {
this.y = dSAPublicKey.getY();
this.dsaSpec = dSAPublicKey.getParams();
}
JDKDSAPublicKey(BigInteger bigInteger, DSAParameterSpec dSAParameterSpec) {
this.y = bigInteger;
this.dsaSpec = dSAParameterSpec;
}
}