### Question:
RSAOAEPPrivateKey extends AbstractPrivateKey { @Override public byte[] decrypt(byte[] ciphertext) throws EncryptionError { if (state == null) { throw new IllegalStateException(); } else { try { return state.decryptor.processBlock(ciphertext, 0, ciphertext.length); } catch (InvalidCipherTextException e) { throw new EncryptionError("decrypt failed", e); } } } RSAOAEPPrivateKey();   RSAOAEPPrivateKey(byte[] e, byte[] p, byte[] q, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); @Override String toString(); @Override void generate(int bitStrength, HashType mgf1HashType); void generate(int bitStrength, byte[] e, int certainty, HashType oaepHashType, HashType mgf1HashType); @Override boolean isInitialized(); @Override int getBitStrength(); @Override AbstractPublicKey getPublicKey(); @Override boolean canDecrypt(); @Override byte[] decrypt(byte[] ciphertext); @Override byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt); @NonNull @Override Map<String, Object> toHash(); @Override void updateFromHash(Map<String, Object> hash); @Override byte[] pack(); static final HashType DEFAULT_OAEP_HASH; static final HashType DEFAULT_MGF1_HASH; }### Answer:
@Test public void decrypt() throws Exception { AbstractPrivateKey rsaPrivateKey = oaepSpec.getPrivateKey(); AbstractPublicKey rsaPublicKey = rsaPrivateKey.getPublicKey(); ((RSAOAEPPrivateKey) rsaPrivateKey).resetDecryptor(); assertArrayEquals(rsaPrivateKey.decrypt(oaepSpec.C), oaepSpec.M); ((RSAOAEPPublicKey) rsaPublicKey).resetEncryptor(); assertArrayEquals(rsaPublicKey.encrypt(oaepSpec.M), oaepSpec.C); AbstractPrivateKey randomPrivateKey = randomPrivateKey4096; AbstractPublicKey randomPublicKey = randomPrivateKey.getPublicKey(); SecureRandom rng = new SecureRandom(); int maxMessageSize = ((RSAOAEPPrivateKey) randomPrivateKey).getMaxBlockSize(), minMessageSize = maxMessageSize, messageSize = (maxMessageSize >= minMessageSize) ? rng.nextInt(maxMessageSize - minMessageSize + 1) + minMessageSize : 0; for (int i = 0; i < NUMBER_OF_RANDOM_ENCRYPTION_DECRYPTION_CYCLES; i++) { ((RSAOAEPPrivateKey) randomPrivateKey).resetDecryptor(); ((RSAOAEPPublicKey) randomPublicKey).resetEncryptor(); byte[] message = new byte[messageSize]; rng.nextBytes(message); byte[] encrypted = randomPublicKey.encrypt(message), decrypted = randomPrivateKey.decrypt(encrypted); assertArrayEquals(decrypted, message); } }