@Test public void testNonNullContextInfo() { HybridEncrypt hybridEncrypt = new RsaEcdsaHybridEncrypt.Builder() .withSenderSigner(senderSigner) .withRecipientPublicKey(recipientPublicKey) .withPadding(Padding.PKCS1) .build(); byte[] plaintext = Random.randBytes(20); byte[] contextInfo = new byte[0]; try { hybridEncrypt.encrypt(plaintext, contextInfo); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException ex) { } }
@Override public byte[] encrypt(byte[] plaintext, byte[] contextInfo ) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] unsignedCiphertext = HybridRsaUtils.encrypt(plaintext, recipientPublicKey, padding, oaepParameterSpec); return signAndSerialize(unsignedCiphertext); } catch (IOException e) { throw new GeneralSecurityException("encryption failed", e); } }
RsaEcdsaHybridEncrypt implements HybridEncrypt { @Override public byte[] encrypt(byte[] plaintext, byte[] contextInfo ) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] unsignedCiphertext = HybridRsaUtils.encrypt(plaintext, recipientPublicKey, padding, oaepParameterSpec); return signAndSerialize(unsignedCiphertext); } catch (IOException e) { throw new GeneralSecurityException("encryption failed", e); } } }
RsaEcdsaHybridEncrypt implements HybridEncrypt { @Override public byte[] encrypt(byte[] plaintext, byte[] contextInfo ) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] unsignedCiphertext = HybridRsaUtils.encrypt(plaintext, recipientPublicKey, padding, oaepParameterSpec); return signAndSerialize(unsignedCiphertext); } catch (IOException e) { throw new GeneralSecurityException("encryption failed", e); } } private  RsaEcdsaHybridEncrypt(Builder builder); }
RsaEcdsaHybridEncrypt implements HybridEncrypt { @Override public byte[] encrypt(byte[] plaintext, byte[] contextInfo ) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] unsignedCiphertext = HybridRsaUtils.encrypt(plaintext, recipientPublicKey, padding, oaepParameterSpec); return signAndSerialize(unsignedCiphertext); } catch (IOException e) { throw new GeneralSecurityException("encryption failed", e); } } private  RsaEcdsaHybridEncrypt(Builder builder); @Override byte[] encrypt(byte[] plaintext, byte[] contextInfo /* unused */); }
RsaEcdsaHybridEncrypt implements HybridEncrypt { @Override public byte[] encrypt(byte[] plaintext, byte[] contextInfo ) throws GeneralSecurityException { if (contextInfo != null) { throw new GeneralSecurityException("contextInfo must be null because it is unused"); } try { byte[] unsignedCiphertext = HybridRsaUtils.encrypt(plaintext, recipientPublicKey, padding, oaepParameterSpec); return signAndSerialize(unsignedCiphertext); } catch (IOException e) { throw new GeneralSecurityException("encryption failed", e); } } private  RsaEcdsaHybridEncrypt(Builder builder); @Override byte[] encrypt(byte[] plaintext, byte[] contextInfo /* unused */);  }