protected static boolean areKeyEquals(PublicKey k1, PublicKey k2) {
if (k1 instanceof DSAPublicKey && k2 instanceof DSAPublicKey) {
DSAPublicKey d1 = (DSAPublicKey) k1;
DSAPublicKey d2 = (DSAPublicKey) k2;
DSAParams p1 = d1.getParams();
DSAParams p2 = d2.getParams();
return d1.getY().equals(d2.getY())
&& p1.getG().equals(p2.getG())
&& p1.getP().equals(p2.getP())
&& p1.getQ().equals(p2.getQ());
} else if (k1 instanceof RSAPublicKey && k2 instanceof RSAPublicKey) {
RSAPublicKey r1 = (RSAPublicKey) k1;
RSAPublicKey r2 = (RSAPublicKey) k2;
return r1.getModulus().equals(r2.getModulus())
&& r1.getPublicExponent().equals(r2.getPublicExponent());