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

95 lines
3.4 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.math.BigInteger;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPublicKeySpec;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.crypto.params.RSAKeyParameters;
import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
import org.bouncycastle.util.Strings;
/* loaded from: classes6.dex */
public class JCERSAPublicKey implements RSAPublicKey {
static final long serialVersionUID = 2675817738516720772L;
private BigInteger modulus;
private BigInteger publicExponent;
public String toString() {
StringBuffer stringBuffer = new StringBuffer("RSA Public Key");
String lineSeparator = Strings.lineSeparator();
stringBuffer.append(lineSeparator);
stringBuffer.append(" modulus: ").append(getModulus().toString(16)).append(lineSeparator);
stringBuffer.append(" public exponent: ").append(getPublicExponent().toString(16)).append(lineSeparator);
return stringBuffer.toString();
}
public int hashCode() {
return getModulus().hashCode() ^ getPublicExponent().hashCode();
}
@Override // java.security.interfaces.RSAPublicKey
public BigInteger getPublicExponent() {
return this.publicExponent;
}
@Override // java.security.interfaces.RSAKey
public BigInteger getModulus() {
return this.modulus;
}
@Override // java.security.Key
public String getFormat() {
return "X.509";
}
@Override // java.security.Key
public byte[] getEncoded() {
return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent()));
}
@Override // java.security.Key
public String getAlgorithm() {
return "RSA";
}
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof RSAPublicKey)) {
return false;
}
RSAPublicKey rSAPublicKey = (RSAPublicKey) obj;
return getModulus().equals(rSAPublicKey.getModulus()) && getPublicExponent().equals(rSAPublicKey.getPublicExponent());
}
JCERSAPublicKey(RSAKeyParameters rSAKeyParameters) {
this.modulus = rSAKeyParameters.getModulus();
this.publicExponent = rSAKeyParameters.getExponent();
}
JCERSAPublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo) {
try {
org.bouncycastle.asn1.pkcs.RSAPublicKey rSAPublicKey = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(subjectPublicKeyInfo.parsePublicKey());
this.modulus = rSAPublicKey.getModulus();
this.publicExponent = rSAPublicKey.getPublicExponent();
} catch (IOException unused) {
throw new IllegalArgumentException("invalid info structure in RSA public key");
}
}
JCERSAPublicKey(RSAPublicKeySpec rSAPublicKeySpec) {
this.modulus = rSAPublicKeySpec.getModulus();
this.publicExponent = rSAPublicKeySpec.getPublicExponent();
}
JCERSAPublicKey(RSAPublicKey rSAPublicKey) {
this.modulus = rSAPublicKey.getModulus();
this.publicExponent = rSAPublicKey.getPublicExponent();
}
}