@Test public void testNonNullContextInfo() throws GeneralSecurityException { HybridEncrypt hybridEncrypt = new RsaEcdsaHybridEncrypt.Builder() .withSenderSigner(senderSigner) .withRecipientPublicKey(recipientPublicKey) .withPadding(Padding.PKCS1) .build(); HybridDecrypt hybridDecrypt = new RsaEcdsaHybridDecrypt.Builder() .withSenderVerifier(senderVerifier) .withRecipientPrivateKey(recipientPrivateKey) .withPadding(Padding.PKCS1) .build(); byte[] plaintext = Random.randBytes(20); byte[] ciphertext = hybridEncrypt.encrypt(plaintext, null); byte[] contextInfo = new byte[0]; try { hybridDecrypt.decrypt(ciphertext, contextInfo); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException ex) { } }
@Override public byte[] decrypt(byte[] ciphertext, byte[] contextInfo) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] verifiedCiphertext = deserializeAndVerify(ciphertext); return HybridRsaUtils.decrypt( verifiedCiphertext, recipientPrivateKey, padding, oaepParameterSpec); } catch (IOException e) { throw new GeneralSecurityException("decryption failed", e); } }
RsaEcdsaHybridDecrypt implements HybridDecrypt { @Override public byte[] decrypt(byte[] ciphertext, byte[] contextInfo) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] verifiedCiphertext = deserializeAndVerify(ciphertext); return HybridRsaUtils.decrypt( verifiedCiphertext, recipientPrivateKey, padding, oaepParameterSpec); } catch (IOException e) { throw new GeneralSecurityException("decryption failed", e); } } }
RsaEcdsaHybridDecrypt implements HybridDecrypt { @Override public byte[] decrypt(byte[] ciphertext, byte[] contextInfo) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] verifiedCiphertext = deserializeAndVerify(ciphertext); return HybridRsaUtils.decrypt( verifiedCiphertext, recipientPrivateKey, padding, oaepParameterSpec); } catch (IOException e) { throw new GeneralSecurityException("decryption failed", e); } } private  RsaEcdsaHybridDecrypt(Builder builder); }
RsaEcdsaHybridDecrypt implements HybridDecrypt { @Override public byte[] decrypt(byte[] ciphertext, byte[] contextInfo) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] verifiedCiphertext = deserializeAndVerify(ciphertext); return HybridRsaUtils.decrypt( verifiedCiphertext, recipientPrivateKey, padding, oaepParameterSpec); } catch (IOException e) { throw new GeneralSecurityException("decryption failed", e); } } private  RsaEcdsaHybridDecrypt(Builder builder); @Override byte[] decrypt(byte[] ciphertext, byte[] contextInfo); }
RsaEcdsaHybridDecrypt implements HybridDecrypt { @Override public byte[] decrypt(byte[] ciphertext, byte[] contextInfo) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] verifiedCiphertext = deserializeAndVerify(ciphertext); return HybridRsaUtils.decrypt( verifiedCiphertext, recipientPrivateKey, padding, oaepParameterSpec); } catch (IOException e) { throw new GeneralSecurityException("decryption failed", e); } } private  RsaEcdsaHybridDecrypt(Builder builder); @Override byte[] decrypt(byte[] ciphertext, byte[] contextInfo);  }