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 ECPublicKey && k2 instanceof ECPublicKey) {
ECPublicKey e1 = (ECPublicKey) k1;
ECPublicKey e2 = (ECPublicKey) k2;
ECParameterSpec p1 = e1.getParams();
ECParameterSpec p2 = e2.getParams();
return p1.getCofactor() == p2.getCofactor()
&& p1.getOrder().equals(p2.getOrder())
&& e1.getW().equals(e2.getW())
&& p1.getGenerator().equals(p2.getGenerator())
&& p1.getCurve().equals(p2.getCurve());
} 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());