コード例 #1
0
  /**
   * Encrypt content, using AES with a random key and a Initialization Vector generated from 'seed'
   * parameter. This method returns the key used for encryption, and stores in database the
   * ID-PATH-NAME tupla that will allow to recover the orignal content only with the returned key
   * (see #doEncryptContent())
   *
   * @param content conted to be encrypted
   * @param name name of the file
   * @param seed value used to genererate the AES Initialization Vector
   * @return struct with reference info of encryptation result
   * @see #doEncryptContent(java.io.InputStream, java.lang.String, byte[])
   */
  public byte[] encryptContent(InputStream content, String name, String seed) {
    try {
      byte[] key = cryptoHelper.getNewKey();
      EncryptedData ed = doEncryptContent(content, name, seed, key);

      createDatabaseRecord(ed);

      return key;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }