code: public String encryptKey(SecretKey key, PublicKey destinationPublicKey) {
  
          // Basic null check
          if (key == null) {
              return null;
          }
  
          // Convert the input key to a byte array:
          byte[] bytes = key.getEncoded();
  
          // Encrypt the bytes:
          byte[] encrypted;
          try {
              Cipher cipher = getCipher(destinationPublicKey);
              encrypted = cipher.doFinal(bytes);
          } catch (IllegalBlockSizeException e) {
              throw new IllegalArgumentException("Error encrypting SecretKey: " + IllegalBlockSizeException.class.getSimpleName(), e);
          } catch (BadPaddingException e) {
              throw new IllegalArgumentException("Error encrypting SecretKey: " + BadPaddingException.class.getSimpleName(), e);
          }
  
          return ByteArray.toBase64(encrypted);
      }
docs: This method encrypts the given {@link SecretKey} with the destination user's
  {@link PublicKey} so that it can be safely sent to them.
  
  @param key                  The {@link SecretKey} to be encrypted.
  @param destinationPublicKey The {@link PublicKey} of the user to whom you will be sending the
  {@link SecretKey}. This can be obtained via {@link Keys#newKeyPair()}.
  @return The encrypted key, as a base64-encoded String, suitable for passing to
  {@link #decryptKey(String, PrivateKey)}.