Java String Encrypt encrypt(String s)

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

Description

encrypt

License

Apache License

Declaration

public static String encrypt(String s) 

Method Source Code

//package com.java2s;
/**/*from  w  ww.  j  ava 2s . c  o  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 encrypt(String s) {
        s = ENCRYPTED_PREFIX + s + ENCRYPTED_SUFFIX;
        StringBuilder rtn = new StringBuilder(s.length());
        byte[] bytes = s.getBytes();
        for (int i = 0; i < bytes.length; i++) {
            rtn.append(encrypt(bytes[i], KEY[i % KEY.length]));
        }
        return rtn.toString();
    }

    private static String encrypt(byte b, byte key) {
        b = (byte) (b ^ key);
        String rtn = Integer.toHexString(b);
        if (rtn.length() == 1) {
            rtn = "0" + rtn;
        }
        return rtn;
    }
}

Related

  1. encrypt(byte[] serialize)
  2. encrypt(char ch)
  3. encrypt(int original, int salt)
  4. encrypt(String data, String key)
  5. encrypt(String inStr)
  6. encrypt(String s)
  7. encrypt(String str)
  8. Encrypt(String str)
  9. Encrypt(String str, String salt)