use of java.security.interfaces.DSAPublicKey in project robovm by robovm.
the class DSAKeyFactoryImpl method engineTranslateKey.
/**
* The method generates a DSAPublicKey object from the provided key.
*
* @param
* key - a DSAPublicKey object or DSAPrivateKey object.
*
* @return
* object of the same type as the "key" argument
*
* @throws InvalidKeyException
* if "key" is neither DSAPublicKey nor DSAPrivateKey
*/
protected Key engineTranslateKey(Key key) throws InvalidKeyException {
if (key != null) {
if (key instanceof DSAPrivateKey) {
DSAPrivateKey privateKey = (DSAPrivateKey) key;
DSAParams params = privateKey.getParams();
try {
return engineGeneratePrivate(new DSAPrivateKeySpec(privateKey.getX(), params.getP(), params.getQ(), params.getG()));
} catch (InvalidKeySpecException e) {
// Actually this exception shouldn't be thrown
throw new InvalidKeyException("ATTENTION: InvalidKeySpecException: " + e);
}
}
if (key instanceof DSAPublicKey) {
DSAPublicKey publicKey = (DSAPublicKey) key;
DSAParams params = publicKey.getParams();
try {
return engineGeneratePublic(new DSAPublicKeySpec(publicKey.getY(), params.getP(), params.getQ(), params.getG()));
} catch (InvalidKeySpecException e) {
// Actually this exception shouldn't be thrown
throw new InvalidKeyException("ATTENTION: InvalidKeySpecException: " + e);
}
}
}
throw new InvalidKeyException("'key' is neither DSAPublicKey nor DSAPrivateKey");
}
use of java.security.interfaces.DSAPublicKey in project robovm by robovm.
the class EncodedKeySpec2Test method isEqual.
private boolean isEqual(Key key1, Key key2) {
if (key1 instanceof DSAPublicKey && key2 instanceof DSAPublicKey) {
DSAPublicKey dsa1 = ((DSAPublicKey) key1);
DSAPublicKey dsa2 = ((DSAPublicKey) key2);
return dsa1.getY().equals(dsa2.getY()) && dsa1.getParams().getG().equals(dsa2.getParams().getG()) && dsa1.getParams().getP().equals(dsa2.getParams().getP()) && dsa1.getParams().getQ().equals(dsa2.getParams().getQ());
} else if (key1 instanceof DSAPrivateKey && key2 instanceof DSAPrivateKey) {
DSAPrivateKey dsa1 = ((DSAPrivateKey) key1);
DSAPrivateKey dsa2 = ((DSAPrivateKey) key2);
return dsa1.getX().equals(dsa2.getX()) && dsa1.getParams().getG().equals(dsa2.getParams().getG()) && dsa1.getParams().getP().equals(dsa2.getParams().getP()) && dsa1.getParams().getQ().equals(dsa2.getParams().getQ());
} else {
return false;
}
}
use of java.security.interfaces.DSAPublicKey in project Conversations by siacs.
the class Account method getOtrFingerprint.
public String getOtrFingerprint() {
if (this.otrFingerprint == null) {
try {
if (this.mOtrService == null) {
return null;
}
final PublicKey publicKey = this.mOtrService.getPublicKey();
if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
return null;
}
this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey).toLowerCase(Locale.US);
return this.otrFingerprint;
} catch (final OtrCryptoException ignored) {
return null;
}
} else {
return this.otrFingerprint;
}
}
use of java.security.interfaces.DSAPublicKey in project XobotOS by xamarin.
the class SHA1withDSA_SignatureImpl method engineInitVerify.
/**
* Initializes this signature object with PublicKey object
* passed as argument to the method.
*
* @params
* publicKey DSAPublicKey object
* @throws
* InvalidKeyException if publicKey is not DSAPublicKey object
*/
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
// parameters and public key
BigInteger p, q, y;
int n1;
if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
throw new InvalidKeyException("publicKey is not an instance of DSAPublicKey");
}
DSAParams params = ((DSAPublicKey) publicKey).getParams();
p = params.getP();
q = params.getQ();
y = ((DSAPublicKey) publicKey).getY();
// checks described in DSA standard
n1 = p.bitLength();
if (p.compareTo(BigInteger.valueOf(1)) != 1 || n1 < 512 || n1 > 1024 || (n1 & 077) != 0) {
throw new InvalidKeyException("bad p");
}
if (q.signum() != 1 || q.bitLength() != 160) {
throw new InvalidKeyException("bad q");
}
if (y.signum() != 1) {
throw new InvalidKeyException("y <= 0");
}
dsaKey = (DSAKey) publicKey;
msgDigest.reset();
}
use of java.security.interfaces.DSAPublicKey in project XobotOS by xamarin.
the class OpenSSLSignature method engineInitVerify.
@Override
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
if (publicKey instanceof DSAPublicKey) {
try {
DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey;
DSAParams dsaParams = dsaPublicKey.getParams();
dsa = NativeCrypto.EVP_PKEY_new_DSA(dsaParams.getP().toByteArray(), dsaParams.getQ().toByteArray(), dsaParams.getG().toByteArray(), dsaPublicKey.getY().toByteArray(), null);
} catch (Exception e) {
throw new InvalidKeyException(e);
}
} else if (publicKey instanceof RSAPublicKey) {
try {
RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
rsa = NativeCrypto.EVP_PKEY_new_RSA(rsaPublicKey.getModulus().toByteArray(), rsaPublicKey.getPublicExponent().toByteArray(), null, null, null);
} catch (Exception e) {
throw new InvalidKeyException(e);
}
} else {
throw new InvalidKeyException("Need DSA or RSA public key");
}
try {
ctx = NativeCrypto.EVP_VerifyInit(evpAlgorithm);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
Aggregations