BigInteger p, q, g, x, y;
DSAParameters dsaParams = param.getParameters();
SecureRandom random = param.getRandom();
q = dsaParams.getQ();
p = dsaParams.getP();
g = dsaParams.getG();
do
{
x = new BigInteger(160, random);
}
while (x.equals(ZERO) || x.compareTo(q) >= 0);
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DSAPublicKeyParameters(y, dsaParams),
new DSAPrivateKeyParameters(x, dsaParams));