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

145 lines
6.9 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.RSAPrivateCrtKey;
import java.security.spec.RSAPrivateCrtKeySpec;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.pkcs.RSAPrivateKey;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
import org.bouncycastle.util.Strings;
/* loaded from: classes6.dex */
public class JCERSAPrivateCrtKey extends JCERSAPrivateKey implements RSAPrivateCrtKey {
static final long serialVersionUID = 7834723820638524718L;
private BigInteger crtCoefficient;
private BigInteger primeExponentP;
private BigInteger primeExponentQ;
private BigInteger primeP;
private BigInteger primeQ;
private BigInteger publicExponent;
public String toString() {
StringBuffer stringBuffer = new StringBuffer("RSA Private CRT 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);
stringBuffer.append(" private exponent: ").append(getPrivateExponent().toString(16)).append(lineSeparator);
stringBuffer.append(" primeP: ").append(getPrimeP().toString(16)).append(lineSeparator);
stringBuffer.append(" primeQ: ").append(getPrimeQ().toString(16)).append(lineSeparator);
stringBuffer.append(" primeExponentP: ").append(getPrimeExponentP().toString(16)).append(lineSeparator);
stringBuffer.append(" primeExponentQ: ").append(getPrimeExponentQ().toString(16)).append(lineSeparator);
stringBuffer.append(" crtCoefficient: ").append(getCrtCoefficient().toString(16)).append(lineSeparator);
return stringBuffer.toString();
}
@Override // org.bouncycastle.jce.provider.JCERSAPrivateKey
public int hashCode() {
return (getModulus().hashCode() ^ getPublicExponent().hashCode()) ^ getPrivateExponent().hashCode();
}
@Override // java.security.interfaces.RSAPrivateCrtKey
public BigInteger getPublicExponent() {
return this.publicExponent;
}
@Override // java.security.interfaces.RSAPrivateCrtKey
public BigInteger getPrimeQ() {
return this.primeQ;
}
@Override // java.security.interfaces.RSAPrivateCrtKey
public BigInteger getPrimeP() {
return this.primeP;
}
@Override // java.security.interfaces.RSAPrivateCrtKey
public BigInteger getPrimeExponentQ() {
return this.primeExponentQ;
}
@Override // java.security.interfaces.RSAPrivateCrtKey
public BigInteger getPrimeExponentP() {
return this.primeExponentP;
}
@Override // org.bouncycastle.jce.provider.JCERSAPrivateKey, java.security.Key
public String getFormat() {
return "PKCS#8";
}
@Override // org.bouncycastle.jce.provider.JCERSAPrivateKey, java.security.Key
public byte[] getEncoded() {
return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()));
}
@Override // java.security.interfaces.RSAPrivateCrtKey
public BigInteger getCrtCoefficient() {
return this.crtCoefficient;
}
@Override // org.bouncycastle.jce.provider.JCERSAPrivateKey
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof RSAPrivateCrtKey)) {
return false;
}
RSAPrivateCrtKey rSAPrivateCrtKey = (RSAPrivateCrtKey) obj;
return getModulus().equals(rSAPrivateCrtKey.getModulus()) && getPublicExponent().equals(rSAPrivateCrtKey.getPublicExponent()) && getPrivateExponent().equals(rSAPrivateCrtKey.getPrivateExponent()) && getPrimeP().equals(rSAPrivateCrtKey.getPrimeP()) && getPrimeQ().equals(rSAPrivateCrtKey.getPrimeQ()) && getPrimeExponentP().equals(rSAPrivateCrtKey.getPrimeExponentP()) && getPrimeExponentQ().equals(rSAPrivateCrtKey.getPrimeExponentQ()) && getCrtCoefficient().equals(rSAPrivateCrtKey.getCrtCoefficient());
}
JCERSAPrivateCrtKey(RSAPrivateCrtKeyParameters rSAPrivateCrtKeyParameters) {
super(rSAPrivateCrtKeyParameters);
this.publicExponent = rSAPrivateCrtKeyParameters.getPublicExponent();
this.primeP = rSAPrivateCrtKeyParameters.getP();
this.primeQ = rSAPrivateCrtKeyParameters.getQ();
this.primeExponentP = rSAPrivateCrtKeyParameters.getDP();
this.primeExponentQ = rSAPrivateCrtKeyParameters.getDQ();
this.crtCoefficient = rSAPrivateCrtKeyParameters.getQInv();
}
JCERSAPrivateCrtKey(RSAPrivateKey rSAPrivateKey) {
this.modulus = rSAPrivateKey.getModulus();
this.publicExponent = rSAPrivateKey.getPublicExponent();
this.privateExponent = rSAPrivateKey.getPrivateExponent();
this.primeP = rSAPrivateKey.getPrime1();
this.primeQ = rSAPrivateKey.getPrime2();
this.primeExponentP = rSAPrivateKey.getExponent1();
this.primeExponentQ = rSAPrivateKey.getExponent2();
this.crtCoefficient = rSAPrivateKey.getCoefficient();
}
JCERSAPrivateCrtKey(PrivateKeyInfo privateKeyInfo) throws IOException {
this(RSAPrivateKey.getInstance(privateKeyInfo.parsePrivateKey()));
}
JCERSAPrivateCrtKey(RSAPrivateCrtKeySpec rSAPrivateCrtKeySpec) {
this.modulus = rSAPrivateCrtKeySpec.getModulus();
this.publicExponent = rSAPrivateCrtKeySpec.getPublicExponent();
this.privateExponent = rSAPrivateCrtKeySpec.getPrivateExponent();
this.primeP = rSAPrivateCrtKeySpec.getPrimeP();
this.primeQ = rSAPrivateCrtKeySpec.getPrimeQ();
this.primeExponentP = rSAPrivateCrtKeySpec.getPrimeExponentP();
this.primeExponentQ = rSAPrivateCrtKeySpec.getPrimeExponentQ();
this.crtCoefficient = rSAPrivateCrtKeySpec.getCrtCoefficient();
}
JCERSAPrivateCrtKey(RSAPrivateCrtKey rSAPrivateCrtKey) {
this.modulus = rSAPrivateCrtKey.getModulus();
this.publicExponent = rSAPrivateCrtKey.getPublicExponent();
this.privateExponent = rSAPrivateCrtKey.getPrivateExponent();
this.primeP = rSAPrivateCrtKey.getPrimeP();
this.primeQ = rSAPrivateCrtKey.getPrimeQ();
this.primeExponentP = rSAPrivateCrtKey.getPrimeExponentP();
this.primeExponentQ = rSAPrivateCrtKey.getPrimeExponentQ();
this.crtCoefficient = rSAPrivateCrtKey.getCrtCoefficient();
}
}