Java String Descrypt decrypt(String s)

Here you can find the source of decrypt(String s)

Description

decrypt

License

Apache License

Declaration

public static String decrypt(String s) 

Method Source Code

//package com.java2s;
/**/*from  w ww  .  j  av a  2s  .co  m*/
 * Copyright ? 2013 - 2017 WaveMaker, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    private static final byte[] KEY = { 12, 7, 28, 127, 97, 69, 77, 122, 11 };
    private static final String ENCRYPTED_PREFIX = "wm_-+";
    private static final String ENCRYPTED_SUFFIX = "==wm-_";

    public static String decrypt(String s) {
        return decrypt(s, true);
    }

    private static String decrypt(String s, boolean removeMarkers) {
        byte[] rtn = new byte[s.length() / 2];
        int j = 0;
        for (int i = 0; i < s.length(); i += 2) {
            String hex = s.substring(i, i + 2);
            rtn[j] = (byte) (Integer.parseInt(hex, 16) ^ KEY[j % KEY.length]);
            j++;
        }
        String d = new String(rtn);
        if (removeMarkers && hasMarkers(d)) {
            return d.substring(ENCRYPTED_PREFIX.length(), d.length() - ENCRYPTED_SUFFIX.length());
        }
        return d;
    }

    private static boolean hasMarkers(String s) {
        return s.startsWith(ENCRYPTED_PREFIX) && s.endsWith(ENCRYPTED_SUFFIX);
    }
}

Related

  1. decrypt(int encrypted, int salt)
  2. decrypt(String arg0)
  3. decrypt(String data, String key)
  4. decrypt(String inString)
  5. decrypt(String s)
  6. decrypt(String s, int offset)
  7. decrypt(String src)
  8. decrypt(String str)
  9. decrypt(String str)