예제 #1
0
  /**
   * decrypt
   *
   * <p>Perform decryption.
   *
   * @param encryptedStr Data to be decrypted.
   * @return Decrypted data.
   */
  public String decrypt(String encryptedStr) {
    byte[] encryptedBytes;
    byte[] decryptedBytes = null;
    String value;

    try {
      encryptedBytes = hexStringToBytes(encryptedStr);
      decryptedBytes = decipher.doFinal(encryptedBytes);
      value = new String(decryptedBytes);
    } catch (Exception e) {
      //
      // Throw exception.
      //
      e.printStackTrace();
      throw CypherException.create(
          logger,
          "Decryption failed",
          e,
          "decrypt",
          EncryptionProvider.class,
          CypherException.PASSWORD_DECRYPT);
    }

    return value;
  }
예제 #2
0
  /**
   * encrypt
   *
   * <p>Perform encryption.
   *
   * @param clearStr Data to be encrypted.
   * @return Encrypted data.
   */
  public String encrypt(String clearStr) {
    byte[] encryptedBytes = null;
    String value;

    try {
      encryptedBytes = encipher.doFinal(clearStr.getBytes("UTF8"));
      value = bytesToHexString(encryptedBytes);
    } catch (Exception e) {
      //
      // Throw exception.
      //
      throw CypherException.create(
          logger,
          "Encryption failed",
          e,
          "encrypt",
          EncryptionProvider.class,
          CypherException.PASSWORD_ENCRYPT);
    }

    return value;
  }