// Path: lib/src/main/java/com/google/capillary/RsaEcdsaConstants.java
// public enum Padding {
//   OAEP("OAEPPadding"),
//   PKCS1("PKCS1Padding");
// 
//   private static final String PREFIX = "RSA/ECB/";
// 
//   private final String padding;
// 
//   Padding(String val) {
//     padding = val;
//   }
// 
//   /**
//    * Returns the current padding enum's transformation string that should be used when calling
//    * {@code javax.crypto.Cipher.getInstance}.
//    *
//    * @return the transformation string.
//    */
//   public String getTransformation() {
//     return PREFIX + padding;
//   }
// }


import com.google.capillary.RsaEcdsaConstants.Padding;
import com.google.capillary.internal.HybridRsaCiphertext;
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.BinaryKeysetReader;
import com.google.crypto.tink.BinaryKeysetWriter;
import com.google.crypto.tink.CleartextKeysetHandle;
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.aead.AeadFactory;
import com.google.crypto.tink.aead.AeadKeyTemplates;
import com.google.crypto.tink.proto.KeyTemplate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.PublicKey;
import javax.crypto.Cipher;
import javax.crypto.spec.OAEPParameterSpec;
/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.capillary;


public final class HybridRsaUtils {

  private static final KeyTemplate SYMMETRIC_KEY_TEMPLATE = AeadKeyTemplates.AES128_GCM;
  private static final byte[] emptyEad = new byte[0];

  /**
   * Encrypts the given plaintext using RSA hybrid encryption.
   *
   * @param plaintext the plaintext to encrypt.
   * @param publicKey the RSA public key.
   * @param padding the RSA padding to use.
   * @param oaepParams the {@link OAEPParameterSpec} to use for OAEP padding.
   * @return the ciphertext.
   * @throws GeneralSecurityException if encryption fails.
   */
  public static byte[] encrypt(
// Path: lib/src/main/java/com/google/capillary/RsaEcdsaConstants.java
// public enum Padding {
//   OAEP("OAEPPadding"),
//   PKCS1("PKCS1Padding");
// 
//   private static final String PREFIX = "RSA/ECB/";
// 
//   private final String padding;
// 
//   Padding(String val) {
//     padding = val;
//   }
// 
//   /**
//    * Returns the current padding enum's transformation string that should be used when calling
//    * {@code javax.crypto.Cipher.getInstance}.
//    *
//    * @return the transformation string.
//    */
//   public String getTransformation() {
//     return PREFIX + padding;
//   }
// }


// Path: lib/src/main/java/com/google/capillary/HybridRsaUtils.java
import com.google.capillary.RsaEcdsaConstants.Padding;
import com.google.capillary.internal.HybridRsaCiphertext;
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.BinaryKeysetReader;
import com.google.crypto.tink.BinaryKeysetWriter;
import com.google.crypto.tink.CleartextKeysetHandle;
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.aead.AeadFactory;
import com.google.crypto.tink.aead.AeadKeyTemplates;
import com.google.crypto.tink.proto.KeyTemplate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.PublicKey;
import javax.crypto.Cipher;
import javax.crypto.spec.OAEPParameterSpec;

/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.capillary;


public final class HybridRsaUtils {

  private static final KeyTemplate SYMMETRIC_KEY_TEMPLATE = AeadKeyTemplates.AES128_GCM;
  private static final byte[] emptyEad = new byte[0];

  /**
   * Encrypts the given plaintext using RSA hybrid encryption.
   *
   * @param plaintext the plaintext to encrypt.
   * @param publicKey the RSA public key.
   * @param padding the RSA padding to use.
   * @param oaepParams the {@link OAEPParameterSpec} to use for OAEP padding.
   * @return the ciphertext.
   * @throws GeneralSecurityException if encryption fails.
   */
  public static byte[] encrypt(
      byte[] plaintext, PublicKey publicKey, Padding padding, OAEPParameterSpec oaepParams)