Пример #1
0
  /**
   * @param aPassword An unencrypted (plain text) password
   * @return An encrypted password
   */
  public static String encrypt(final String aPassword) {

    String retVal = null;
    final MessageDigest tmpDigest = Password.getInstance();

    if (aPassword != null) {

      final byte[] tmpBytes = tmpDigest.digest(aPassword.getBytes());

      for (int i = 0; i < tmpBytes.length; i++) {

        if (tmpBytes[i] < 0) {
          tmpBytes[i] = (byte) (tmpBytes[i] + 128);
        }
        if (tmpBytes[i] < 32) {
          tmpBytes[i] = (byte) (tmpBytes[i] + 32);
        }
        // REMOVE!!!
        // 34 is "
        // 38 is &
        // 39 is '
        // 47 is /
        // 60 is <
        // 62 is >
        // 92 is \
        // REMOVE!!!
        if ((tmpBytes[i] == 34)
            || (tmpBytes[i] == 38)
            || (tmpBytes[i] == 39)
            || (tmpBytes[i] == 47)
            || (tmpBytes[i] == 60)
            || (tmpBytes[i] == 62)
            || (tmpBytes[i] == 92)) {
          tmpBytes[i] = 32;
        }
      }

      retVal = new String(tmpBytes).trim();
    }

    return retVal;
  }
Пример #2
0
  /**
   * @param aPassword An unencrypted (plain text) password
   * @param aToBytesEncoding
   * @param aFromBytesEncoding
   * @return An encrypted password
   */
  public static String encrypt(
      final String aPassword, final String aToBytesEncoding, final String aFromBytesEncoding) {

    String retVal = null;
    final MessageDigest tmpDigest = Password.getInstance();

    if (aPassword != null) {

      try {

        final byte[] tmpBytes = tmpDigest.digest(aPassword.getBytes(aToBytesEncoding));

        retVal = new String(tmpBytes, aFromBytesEncoding).trim();

      } catch (final UnsupportedEncodingException anE) {
        BasicLogger.error(anE.toString());
      }
    }

    return retVal;
  }