122 lines
4.8 KiB
Java
122 lines
4.8 KiB
Java
|
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.RSAPrivateKey;
|
||
|
import java.security.spec.RSAPrivateKeySpec;
|
||
|
import java.util.Enumeration;
|
||
|
import org.bouncycastle.asn1.ASN1Encodable;
|
||
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||
|
import org.bouncycastle.asn1.DERNull;
|
||
|
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
|
||
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||
|
import org.bouncycastle.crypto.params.RSAKeyParameters;
|
||
|
import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
|
||
|
import org.bouncycastle.jcajce.provider.asymmetric.util.PKCS12BagAttributeCarrierImpl;
|
||
|
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class JCERSAPrivateKey implements RSAPrivateKey, PKCS12BagAttributeCarrier {
|
||
|
private static BigInteger ZERO = BigInteger.valueOf(0);
|
||
|
static final long serialVersionUID = 5110188922551353628L;
|
||
|
private PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
||
|
protected BigInteger modulus;
|
||
|
protected BigInteger privateExponent;
|
||
|
|
||
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
||
|
public void setBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier, ASN1Encodable aSN1Encodable) {
|
||
|
this.attrCarrier.setBagAttribute(aSN1ObjectIdentifier, aSN1Encodable);
|
||
|
}
|
||
|
|
||
|
public int hashCode() {
|
||
|
return getModulus().hashCode() ^ getPrivateExponent().hashCode();
|
||
|
}
|
||
|
|
||
|
@Override // java.security.interfaces.RSAPrivateKey
|
||
|
public BigInteger getPrivateExponent() {
|
||
|
return this.privateExponent;
|
||
|
}
|
||
|
|
||
|
@Override // java.security.interfaces.RSAKey
|
||
|
public BigInteger getModulus() {
|
||
|
return this.modulus;
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public String getFormat() {
|
||
|
return "PKCS#8";
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public byte[] getEncoded() {
|
||
|
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);
|
||
|
BigInteger modulus = getModulus();
|
||
|
BigInteger bigInteger = ZERO;
|
||
|
BigInteger privateExponent = getPrivateExponent();
|
||
|
BigInteger bigInteger2 = ZERO;
|
||
|
return KeyUtil.getEncodedPrivateKeyInfo(algorithmIdentifier, new org.bouncycastle.asn1.pkcs.RSAPrivateKey(modulus, bigInteger, privateExponent, bigInteger2, bigInteger2, bigInteger2, bigInteger2, bigInteger2));
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
||
|
public Enumeration getBagAttributeKeys() {
|
||
|
return this.attrCarrier.getBagAttributeKeys();
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
||
|
public ASN1Encodable getBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier) {
|
||
|
return this.attrCarrier.getBagAttribute(aSN1ObjectIdentifier);
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public String getAlgorithm() {
|
||
|
return "RSA";
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (!(obj instanceof RSAPrivateKey)) {
|
||
|
return false;
|
||
|
}
|
||
|
if (obj == this) {
|
||
|
return true;
|
||
|
}
|
||
|
RSAPrivateKey rSAPrivateKey = (RSAPrivateKey) obj;
|
||
|
return getModulus().equals(rSAPrivateKey.getModulus()) && getPrivateExponent().equals(rSAPrivateKey.getPrivateExponent());
|
||
|
}
|
||
|
|
||
|
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
|
||
|
objectOutputStream.writeObject(this.modulus);
|
||
|
this.attrCarrier.writeObject(objectOutputStream);
|
||
|
objectOutputStream.writeObject(this.privateExponent);
|
||
|
}
|
||
|
|
||
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||
|
this.modulus = (BigInteger) objectInputStream.readObject();
|
||
|
PKCS12BagAttributeCarrierImpl pKCS12BagAttributeCarrierImpl = new PKCS12BagAttributeCarrierImpl();
|
||
|
this.attrCarrier = pKCS12BagAttributeCarrierImpl;
|
||
|
pKCS12BagAttributeCarrierImpl.readObject(objectInputStream);
|
||
|
this.privateExponent = (BigInteger) objectInputStream.readObject();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public JCERSAPrivateKey(RSAKeyParameters rSAKeyParameters) {
|
||
|
this.modulus = rSAKeyParameters.getModulus();
|
||
|
this.privateExponent = rSAKeyParameters.getExponent();
|
||
|
}
|
||
|
|
||
|
JCERSAPrivateKey(RSAPrivateKeySpec rSAPrivateKeySpec) {
|
||
|
this.modulus = rSAPrivateKeySpec.getModulus();
|
||
|
this.privateExponent = rSAPrivateKeySpec.getPrivateExponent();
|
||
|
}
|
||
|
|
||
|
JCERSAPrivateKey(RSAPrivateKey rSAPrivateKey) {
|
||
|
this.modulus = rSAPrivateKey.getModulus();
|
||
|
this.privateExponent = rSAPrivateKey.getPrivateExponent();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: protected */
|
||
|
public JCERSAPrivateKey() {
|
||
|
}
|
||
|
}
|