// encoded test
//
KeyFactory f = KeyFactory.getInstance("GOST3410", "BC");
X509EncodedKeySpec x509s = new X509EncodedKeySpec(vKey.getEncoded());
GOST3410PublicKey k1 = (GOST3410PublicKey)f.generatePublic(x509s);
if (!k1.getY().equals(((GOST3410PublicKey)vKey).getY()))
{
fail("public number not decoded properly");
}
if (!k1.getParameters().equals(((GOST3410PublicKey)vKey).getParameters()))
{
fail("public parameters not decoded properly");
}
PKCS8EncodedKeySpec pkcs8 = new PKCS8EncodedKeySpec(sKey.getEncoded());
GOST3410PrivateKey k2 = (GOST3410PrivateKey)f.generatePrivate(pkcs8);
if (!k2.getX().equals(((GOST3410PrivateKey)sKey).getX()))
{
fail("private number not decoded properly");
}
if (!k2.getParameters().equals(((GOST3410PrivateKey)sKey).getParameters()))
{
fail("private number not decoded properly");
}
k2 = (GOST3410PrivateKey)serializeDeserialize(sKey);
if (!k2.getX().equals(((GOST3410PrivateKey)sKey).getX()))
{
fail("private number not deserialised properly");
}
if (!k2.getParameters().equals(((GOST3410PrivateKey)sKey).getParameters()))
{
fail("private number not deserialised properly");
}
checkEquals(k2, sKey);
if (!(k2 instanceof PKCS12BagAttributeCarrier))
{
fail("private key not implementing PKCS12 attribute carrier");
}
k1 = (GOST3410PublicKey)serializeDeserialize(vKey);
if (!k1.getY().equals(((GOST3410PublicKey)vKey).getY()))
{
fail("public number not deserialised properly");
}
if (!k1.getParameters().equals(((GOST3410PublicKey)vKey).getParameters()))
{
fail("public parameters not deserialised properly");
}
checkEquals(k1, vKey);