KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class);
final SecureRandom secureRandom = createMock(SecureRandom.class);
expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator).anyTimes();
rsaKeyPairGenerator.initialize(2048, secureRandom);
expectLastCall().anyTimes();
expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair).anyTimes();
replay(crypto, rsaKeyPairGenerator, secureRandom);
binder.bind(Crypto.class).toInstance(crypto);
binder.bind(SecureRandom.class).toInstance(secureRandom);
} catch (NoSuchAlgorithmException e) {
propagate(e);