<p>Encrypts file.</p>
@param pFilePath File Path
@param pEncryptedPath Encrypted Path
@throws Exception - an exception
499619
@Override
  public final void encryptFile(final String pFilePath,
    final String pEncryptedPath) throws Exception {
    KeyGenerator keyGenAes = KeyGenerator.
      getInstance("AES", this.cryptoProvider);
    keyGenAes.init(256, new SecureRandom());
    SecretKey sskAes = keyGenAes.generateKey();
    Cipher cipherRsa = Cipher.getInstance("RSA", this.cryptoProvider);
    cipherRsa.init(Cipher.ENCRYPT_MODE, lazyGetPublicKeyAnotherAjetty());
    byte[] encryptedSsk = cipherRsa.doFinal(sskAes.getEncoded());
    Signature sigMk = Signature.getInstance("SHA256withRSA");
    sigMk.initSign(lazyGetOurPrivateKey(), new SecureRandom());
    sigMk.update(encryptedSsk);
    byte[] sigSsk = sigMk.sign();
    Cipher cipherAes = Cipher.getInstance("AES/ECB/PKCS7Padding",
      this.cryptoProvider);
    cipherAes.init(Cipher.ENCRYPT_MODE, sskAes);
    BufferedInputStream bis = null;
    CipherOutputStream cous = null;
    byte[] buffer = new byte[1024];
    int len;
    try {
      bis = new BufferedInputStream(new FileInputStream(pFilePath));
      cous = new CipherOutputStream(new FileOutputStream(pEncryptedPath),
        cipherAes);
      while ((len = bis.read(buffer)) > 0) {
        cous.write(buffer, 0, len);
      }
      cous.flush();
    } finally {
      if (bis != null) {
        try {
          bis.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      if (cous != null) {
        try {
          cous.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    bis = null;
    try {
      sigMk.initSign(lazyGetOurPrivateKey(), new SecureRandom());
      bis = new BufferedInputStream(new FileInputStream(pEncryptedPath));
      while ((len = bis.read(buffer)) > 0) {
        sigMk.update(buffer, 0, len);
      }
    } finally {
      if (bis != null) {
        try {
          bis.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    byte[] sigDt = sigMk.sign();
    // write SSK, signatures
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(pEncryptedPath + ".sken");
      fos.write(encryptedSsk);
      fos.flush();
    } finally {
      if (fos != null) {
        try {
          fos.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    fos = null;
    try {
      fos = new FileOutputStream(pEncryptedPath + ".sken.sig");
      fos.write(sigSsk);
      fos.flush();
    } finally {
      if (fos != null) {
        try {
          fos.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    fos = null;
    try {
      fos = new FileOutputStream(pEncryptedPath + ".sig");
      fos.write(sigDt);
      fos.flush();
    } finally {
      if (fos != null) {
        try {
          fos.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
455706
@Override
  public void setPermission(Path p, FsPermission permission
      ) throws IOException {
    FsAction user = permission.getUserAction();
    FsAction group = permission.getGroupAction();
    FsAction other = permission.getOtherAction();
    
    File f = pathToFile(p);
    
    // Fork chmod if group and other permissions are different...
    if (group != other) {
      execSetPermission(f, permission);
      return;
    }
    
    boolean rv = true;
    
    // read perms
    rv = f.setReadable(group.implies(FsAction.READ), false);
    checkReturnValue(rv, p, permission);
    if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
      f.setReadable(user.implies(FsAction.READ), true);
      checkReturnValue(rv, p, permission);
    }

    // write perms
    rv = f.setWritable(group.implies(FsAction.WRITE), false);
    checkReturnValue(rv, p, permission);
    if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
      f.setWritable(user.implies(FsAction.WRITE), true);
      checkReturnValue(rv, p, permission);
    }

    // exec perms
    rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
    checkReturnValue(rv, p, permission);
    if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
      f.setExecutable(user.implies(FsAction.EXECUTE), true);
      checkReturnValue(rv, p, permission);
    }
  }
671486
void parseOneFile(final Path inputPath, final File outputFolder) throws IOException {
    try (final TFile.Reader.Scanner scanner = this.getScanner(inputPath)) {
      while (!scanner.atEnd()) {
        new LogFileEntry(scanner.entry()).write(outputFolder);
        scanner.advance();
      }
    }
  }
1292432
public void addFile(String path, InputStream inputStream) throws IOException {
    addFile(path, inputStream, null);
  }
375082
protected static final byte[] encrypt(byte[] data, byte[] key, String cipher) throws Exception {
        SecretKey sKey = constructSecretKey(key, cipher);
        Cipher ci = createCipher(Cipher.ENCRYPT_MODE, key, cipher, sKey);
        return ci.doFinal(data);
    }
929135
private static void loadFile(String filePath) {
        final Path path = FileSystems.getDefault().getPath(filePath);

        try {
            data.clear();
            data.load(Files.newBufferedReader(path));
        } catch(IOException e) {
            LOG.warn("Exception while loading " + path.toString(), e);
        }
    }
228023
private static byte[] encryptData(PublicKey publicKey, byte[] plainData)
			throws Exception {
		try {
			Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding","BC");
			cipher.init(Cipher.ENCRYPT_MODE, publicKey);
			return cipher.doFinal(plainData);
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		}
	}
185870
public void encryptFile(File file, boolean replace) throws MissingParameterException, IOException {

		if(file == null || !file.exists()){
			throw new MissingParameterException("File not specified or file does not exist.");
		}
		
		FileInputStream fis = new FileInputStream(file);
		
		ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
		
		encryptStream(fis, baos);
		
		File tmpEncrypted = File.createTempFile("commonsencryption", RandomStringUtils.randomAlphanumeric(10));
		
		if(!tmpEncrypted.exists()){
			throw new IOException("Failed to encrypt file.");
		}
		
		FileOutputStream fos = new FileOutputStream(tmpEncrypted);
		
		IOUtils.write(baos.toByteArray(),fos);
		
		fos.close();
		
		if(replace){
			File bkpFile = FileUtils.getFile(file.getAbsolutePath() + ".bkp");
			FileUtils.moveFile(file, bkpFile);
			
			try{
			
				FileUtils.moveFile(tmpEncrypted, FileUtils.getFile(file.getAbsolutePath()));
			
			}catch(IOException e){
				throw new IOException("Failed to encrypt file. Existing file saved with \".bkp\": " + e.getMessage(),e);
			}
			
			bkpFile.delete();
			
		}else{
			
			FileUtils.moveFile(tmpEncrypted, FileUtils.getFile(file.getAbsolutePath() + ".encrypted"));
			
		}
		
	}
806454
public static byte[] encrypt(byte[] data, byte[] key) throws Exception{
		//恢复密钥
		SecretKey secretKey = new SecretKeySpec(key, "AES");
		//Cipher完成加密
		Cipher cipher = Cipher.getInstance("AES");
		//根据密钥对cipher进行初始化
		cipher.init(Cipher.ENCRYPT_MODE, secretKey);
		//加密
		byte[] encrypt = cipher.doFinal(data);
		
		return encrypt;
	}
1111575
public static byte[] encryptAsBytes(final String plainText) throws Exception {
        final SecretKey secretKey = KeyManager.getInstance().getSecretKey();
        return encryptAsBytes(secretKey, plainText);
    }
289363
public void readFrom(File keyFile) throws IOException, GeneralSecurityException {
        final String password = isPemEncrypted(keyFile)
                ? askForPasswd(keyFile.getCanonicalPath())
                : null
        ;
        privateKeys.add(loadKey(keyFile, password));
    }
1082693
public void decompress(String path)
		throws IOException
	{
		File bzip2 = new File(path);

		//
		File unarchived = new File(bzip2.getName().replace(".bz2", ""));

		unarchived.createNewFile();

		BufferedInputStream inputStr = new BufferedInputStream(new FileInputStream(bzip2));

		// read bzip2 prefix
		inputStr.read();
		inputStr.read();

		BufferedInputStream buffStr = new BufferedInputStream(inputStr);

		CBZip2InputStream input = new CBZip2InputStream(buffStr);

		FileOutputStream outStr = new FileOutputStream(unarchived);

		while (true) {
			byte[] compressedBytes = new byte[DECOMPRESSION_CACHE];

			int byteRead = input.read(compressedBytes);

			outStr.write(compressedBytes, 0, byteRead);
			if (byteRead != DECOMPRESSION_CACHE) {
				break;
			}
		}

		input.close();
		buffStr.close();
		inputStr.close();
		outStr.close();
	}
785714
public void addFile(String path, InputStream inputStream, String contentType) throws IOException {
    String fullPath = buildJcrPathForZip(path);
    writeBinaryFile(fullPath, inputStream);

    if (StringUtils.isNotEmpty(contentType)) {
      String mimeType = StringUtils.substringBefore(contentType, CONTENT_TYPE_CHARSET_EXTENSION);
      String encoding = StringUtils.substringAfter(contentType, CONTENT_TYPE_CHARSET_EXTENSION);

      String fullPathMetadata = fullPath + DOT_DIR_FOLDER + "/" + DOT_CONTENT_XML;
      Document doc = xmlContentBuilder.buildNtFile(mimeType, encoding);
      writeXmlDocument(fullPathMetadata, doc);
    }
  }
452302
public static String encodePath(String path) throws NullPointerException {
		return new String(encode(path, UriComponentEncoderBitSets.allowed_abs_path));
	}
622323
public void ENsavehydfile( String filePath ) throws EpanetException {
        int err = epanet.ENsavehydfile(filePath);
        checkError(err);
    }
965388
public static String getEntireFileSha1(String filePath) throws Exception {
		InputStream fileInputStream = null;
		try {
			fileInputStream = CommonFileUtils.getFileInputStream(filePath);
			String sha1Digest = DigestUtils.sha1Hex(fileInputStream);
			return sha1Digest;
		} catch (Exception e) {
			String errMsg = "getFileSha1 occur a exception, file:" + filePath + ", exception:" + e.toString();
			LOG.error(errMsg);
			throw new Exception(errMsg);
		} finally {
			try {
				CommonFileUtils.closeFileStream(fileInputStream, filePath);
			} catch (Exception e) {
				throw e;
			}
		}
	}
432307
public void setEscapedPath(String escapedPath) throws URIException {
        if (escapedPath == null) {
            _path = _opaque = null;
            setURI();
            return;
        }
        setRawPath(escapedPath.toCharArray());
    }