use of com.icodici.crypto.AbstractPublicKey in project universa by UniversaBlockchain.
the class RSAOAEPPublicKeyTest method updateFromHashGoodRSASpec.
/**
* Test {@link RSAOAEPPublicKey#updateFromHash} on success scenarios,
* using RSA spec vectors.
*/
@Test
public void updateFromHashGoodRSASpec() throws Exception {
Map mapRSA = new HashMap<String, Object>() {
{
put("n", oaepSpec.n);
put("e", oaepSpec.e);
put("hash", "SHA-1");
put("mgf1Hash", "SHA-1");
}
};
AbstractPublicKey rsaPublicKey = new RSAOAEPPublicKey();
rsaPublicKey.updateFromHash(mapRSA);
// We've read the public key from hash;
// but, to test it over the RSA spec vectors,
// we need to hack into the state.rng (and substitute it with our custom one),
// even though it is declared as final.
RSAOAEPPublicKey.State state = ((RSAOAEPPublicKey) rsaPublicKey).state;
Field rngField = RSAOAEPPublicKey.State.class.getDeclaredField("rng");
rngField.setAccessible(true);
rngField.set(state, oaepSpec.getRandSeed());
// Now we can even test the encryption on the RSA spec vectors.
assertTrue(rsaPublicKey.isInitialized());
assertEquals(rsaPublicKey.getBitStrength(), 1024);
((RSAOAEPPublicKey) rsaPublicKey).resetEncryptor();
assertArrayEquals(rsaPublicKey.encrypt(oaepSpec.M), oaepSpec.C);
}
Aggregations