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

108 lines
4.4 KiB
Java
Raw 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 javax.crypto.interfaces.DHPublicKey;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.DHPublicKeySpec;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.oiw.ElGamalParameter;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.crypto.params.ElGamalPublicKeyParameters;
import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
import org.bouncycastle.jce.interfaces.ElGamalPublicKey;
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
import org.bouncycastle.jce.spec.ElGamalPublicKeySpec;
/* loaded from: classes6.dex */
public class JCEElGamalPublicKey implements ElGamalPublicKey, DHPublicKey {
static final long serialVersionUID = 8712728417091216948L;
private ElGamalParameterSpec elSpec;
private BigInteger y;
@Override // org.bouncycastle.jce.interfaces.ElGamalPublicKey, javax.crypto.interfaces.DHPublicKey
public BigInteger getY() {
return this.y;
}
@Override // javax.crypto.interfaces.DHKey
public DHParameterSpec getParams() {
return new DHParameterSpec(this.elSpec.getP(), this.elSpec.getG());
}
@Override // org.bouncycastle.jce.interfaces.ElGamalKey
public ElGamalParameterSpec getParameters() {
return this.elSpec;
}
@Override // java.security.Key
public String getFormat() {
return "X.509";
}
@Override // java.security.Key
public byte[] getEncoded() {
return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(this.elSpec.getP(), this.elSpec.getG())), new ASN1Integer(this.y));
}
@Override // java.security.Key
public String getAlgorithm() {
return "ElGamal";
}
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
objectOutputStream.writeObject(getY());
objectOutputStream.writeObject(this.elSpec.getP());
objectOutputStream.writeObject(this.elSpec.getG());
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
this.y = (BigInteger) objectInputStream.readObject();
this.elSpec = new ElGamalParameterSpec((BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject());
}
JCEElGamalPublicKey(ElGamalPublicKeySpec elGamalPublicKeySpec) {
this.y = elGamalPublicKeySpec.getY();
this.elSpec = new ElGamalParameterSpec(elGamalPublicKeySpec.getParams().getP(), elGamalPublicKeySpec.getParams().getG());
}
JCEElGamalPublicKey(ElGamalPublicKey elGamalPublicKey) {
this.y = elGamalPublicKey.getY();
this.elSpec = elGamalPublicKey.getParameters();
}
JCEElGamalPublicKey(ElGamalPublicKeyParameters elGamalPublicKeyParameters) {
this.y = elGamalPublicKeyParameters.getY();
this.elSpec = new ElGamalParameterSpec(elGamalPublicKeyParameters.getParameters().getP(), elGamalPublicKeyParameters.getParameters().getG());
}
JCEElGamalPublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo) {
ElGamalParameter elGamalParameter = ElGamalParameter.getInstance(subjectPublicKeyInfo.getAlgorithm().getParameters());
try {
this.y = ((ASN1Integer) subjectPublicKeyInfo.parsePublicKey()).getValue();
this.elSpec = new ElGamalParameterSpec(elGamalParameter.getP(), elGamalParameter.getG());
} catch (IOException unused) {
throw new IllegalArgumentException("invalid info structure in DSA public key");
}
}
JCEElGamalPublicKey(DHPublicKeySpec dHPublicKeySpec) {
this.y = dHPublicKeySpec.getY();
this.elSpec = new ElGamalParameterSpec(dHPublicKeySpec.getP(), dHPublicKeySpec.getG());
}
JCEElGamalPublicKey(DHPublicKey dHPublicKey) {
this.y = dHPublicKey.getY();
this.elSpec = new ElGamalParameterSpec(dHPublicKey.getParams().getP(), dHPublicKey.getParams().getG());
}
JCEElGamalPublicKey(BigInteger bigInteger, ElGamalParameterSpec elGamalParameterSpec) {
this.y = bigInteger;
this.elSpec = elGamalParameterSpec;
}
}