Exemple #1
0
 /** ** Scrambles String */
 public static String _ens64(String d) {
   if (!StringTools.isBlank(d)) {
     return Base64.encode(StringTools.getBytes(d), getBase64Alphabet(), Base64Pad);
   } else {
     return "";
   }
 }
Exemple #2
0
  /**
   * @param s
   * @return
   * @throws GeneralSecurityException
   * @throws UnsupportedEncodingException
   */
  public static String decrypt(final String s)
      throws GeneralSecurityException, UnsupportedEncodingException {
    String decrypted = null;

    try {
      if (s != null) {
        final SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        final SecretKey secretKey =
            secretKeyFactory.generateSecret(new PBEKeySpec(secret.toCharArray()));
        final Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey, new PBEParameterSpec(SALT, 20));
        final byte[] stringBytes = s.getBytes("UTF-8");
        final byte[] decodedBytes = Base64.decode(stringBytes, Base64.DEFAULT);
        final byte[] decryptedBytes = cipher.doFinal(decodedBytes);
        decrypted = new String(decryptedBytes, "UTF-8");
      }
    } catch (GeneralSecurityException x) {
      throw x;
    } catch (UnsupportedEncodingException x) {
      throw x;
    } catch (Exception x) {
      DBG.m(x);
    }

    return decrypted;
  }
Exemple #3
0
 /** ** Descrambles String */
 public static String _des64(String e) {
   if (!StringTools.isBlank(e)) {
     byte b[] = Base64.decode(e, getBase64Alphabet(), Base64Pad);
     return StringTools.toStringValue(b, ' ');
   } else {
     return "";
   }
 }
Exemple #4
0
 /** ** Descrambles String */
 public static String _des64(String e) {
   if (!StringTools.isBlank(e)) {
     try {
       byte b[] = Base64.decode(e, getBase64Alphabet(), Base64Pad);
       return StringTools.toStringValue(b, ' ');
     } catch (Base64.Base64DecodeException bde) {
       Print.logError("Invalid Base64 characters", bde);
       return "";
     }
   } else {
     return "";
   }
 }
Exemple #5
0
 /** ** Gets the scrambled Base64 alphabet ** @return The scrambled Base64 alphabet */
 private static char[] getBase64Alphabet() {
   if (Base64Alphabet == null) {
     BigInteger seed = RTConfig.getBigInteger(PROP_uriArgScrambleSeed, DefaultScrambleSeed);
     Base64Alphabet = Base64.shuffleAlphabet(seed);
     for (int i = 0; i < Base64Alphabet.length; i++) {
       if (Base64Alphabet[i] == '+') {
         Base64Alphabet[i] = '-';
       } else if (Base64Alphabet[i] == '/') {
         Base64Alphabet[i] = '_';
       }
     }
     // Print.logInfo("Base64 Alpha ["+seed+"]: "+StringTools.toStringValue(Base64Alphabet));
   }
   return Base64Alphabet;
 };