public boolean validate () {
		
		// check primes.
		BigInteger mm = p.multiply(q);
		if (!mm.equals (m))
			return false;
		
		BigInteger pm1 = p.subtract (BigInteger.ONE);
        BigInteger qm1 = q.subtract (BigInteger.ONE);
        BigInteger r = pm1.multiply(qm1).divide(pm1.gcd(qm1));

        // check public exponent.
        if (!r.gcd (e).equals (BigInteger.ONE))
        	return false;

        // check private exponent
        BigInteger dd = e.modInverse (r);
		if (!dd.equals (d)) {
			// probably just a different representation
			BigInteger x = d.mod(r);
			if (!x.equals(dd))
				return false;
		}
		
		// check prime exponents and coefficient
		BigInteger pEE = e.modInverse (pm1);
		if (!pEE.equals (pE))
			return false;
		BigInteger qEE = e.modInverse (qm1);
		if (!qEE.equals (qE))
			return false;
		BigInteger coeff = (q.compareTo(p) < 0 ? q.modInverse(p) : p.modInverse(q));
		return coeff.equals (crt);
	}