Java Encrypt String encrypt(String s)

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

Description

encrypt

License

CDDL license

Declaration

public final static String encrypt(String s) 

Method Source Code


//package com.java2s;
//License from project: CDDL license 

import java.io.*;

public class Main {
    private final static int Crypt1 = 52895, Crypt2 = 22419;
    private final static int Cryptkey = 23647;

    public final static String encrypt(String s) {
        return encrypt(s, Cryptkey);
    }//from   ww  w  .j  a v  a 2 s. c om

    public static String encrypt(String s, long key) {
        if (s == null || s.length() < 1)
            return null;
        ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
        for (int i = 0; i < s.length(); i++) {
            char decr = (char) s.charAt(i);
            char encr = (char) ((decr ^ key) & 0xff);
            key = (long) ((encr + key) * Crypt1 + Crypt2);
            out.write('%');
            out.write(Character.forDigit(encr >> 4, 16));
            out.write(Character.forDigit(encr & 0xF, 16));
        }
        return out.toString();
    }
}

Related

  1. encrypt(String str)
  2. encrypt(String value)
  3. encryptString(String message)