52 lines
2.4 KiB
Java
52 lines
2.4 KiB
Java
|
package org.bouncycastle.jcajce.provider.asymmetric.dsa;
|
||
|
|
||
|
import java.security.InvalidKeyException;
|
||
|
import java.security.PrivateKey;
|
||
|
import java.security.PublicKey;
|
||
|
import java.security.interfaces.DSAPrivateKey;
|
||
|
import java.security.interfaces.DSAPublicKey;
|
||
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||
|
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
|
||
|
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
|
||
|
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
||
|
import org.bouncycastle.crypto.params.DSAParameters;
|
||
|
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
|
||
|
import org.bouncycastle.crypto.params.DSAPublicKeyParameters;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class DSAUtil {
|
||
|
public static final ASN1ObjectIdentifier[] dsaOids = {X9ObjectIdentifiers.id_dsa, OIWObjectIdentifiers.dsaWithSHA1};
|
||
|
|
||
|
public static boolean isDsaOid(ASN1ObjectIdentifier aSN1ObjectIdentifier) {
|
||
|
int i = 0;
|
||
|
while (true) {
|
||
|
ASN1ObjectIdentifier[] aSN1ObjectIdentifierArr = dsaOids;
|
||
|
if (i == aSN1ObjectIdentifierArr.length) {
|
||
|
return false;
|
||
|
}
|
||
|
if (aSN1ObjectIdentifier.equals(aSN1ObjectIdentifierArr[i])) {
|
||
|
return true;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey publicKey) throws InvalidKeyException {
|
||
|
if (publicKey instanceof DSAPublicKey) {
|
||
|
DSAPublicKey dSAPublicKey = (DSAPublicKey) publicKey;
|
||
|
return new DSAPublicKeyParameters(dSAPublicKey.getY(), new DSAParameters(dSAPublicKey.getParams().getP(), dSAPublicKey.getParams().getQ(), dSAPublicKey.getParams().getG()));
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder("can't identify DSA public key: ");
|
||
|
sb.append(publicKey.getClass().getName());
|
||
|
throw new InvalidKeyException(sb.toString());
|
||
|
}
|
||
|
|
||
|
public static AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey privateKey) throws InvalidKeyException {
|
||
|
if (!(privateKey instanceof DSAPrivateKey)) {
|
||
|
throw new InvalidKeyException("can't identify DSA private key.");
|
||
|
}
|
||
|
DSAPrivateKey dSAPrivateKey = (DSAPrivateKey) privateKey;
|
||
|
return new DSAPrivateKeyParameters(dSAPrivateKey.getX(), new DSAParameters(dSAPrivateKey.getParams().getP(), dSAPrivateKey.getParams().getQ(), dSAPrivateKey.getParams().getG()));
|
||
|
}
|
||
|
}
|