Java Utililty Methods String Encrypt

List of utility methods to do String Encrypt

Description

The list of methods to do String Encrypt are organized into topic(s).

Method

Stringencrypt(String str)
Encrypt the given string in a way which anybody having access to this method algorithm can easily decrypt.
if (str == null) {
    return null;
StringBuffer buf = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (c >= SHIFTS.length) {
        throw new IllegalArgumentException(
...
StringEncrypt(String str, String salt)
Encrypt
String encoderText = "lsedfoglkwjemc-091324jlkmsda-0sd=1234;l;lsdkOPIER203-4LKJSLDJAS0D925JKNNC,MANSLDJQ32ELK1N4SAIp089er0234lkjo9df82l3kjlknf,nzxc,mn;lasdj9wquelq;d]qowe[;wq;qkwellsdkfj0-0POPOAR0W8RPOp-02@#$sdklj$#)0asdlksadLKJFA9820934)(&$3ij09sdj34-sdfj2po345-09dlkfjlkv,mxncv;laskdkl/a;au093hakjh2389~!@%&*%#&^539478(*&)^(&^_*8-*_+++|78w3ihsdnmnclksdj)(*#%*_@$(+#@$)&@#^*&^#@$()(*#@$HDFIkdhfgkjh098k;ldsk.sdv.c,msd;flkp0w34;2lk-=sd0p121o39-werl2k3;4lj09sdflskjlekfj,mv,mcxvjlksjdflksjdl*(#@!&akhduyqweperilmmdxcasnd*(#@9879327kjhasudfewr kwehriwueyrhc ausdgiq7w8e71 cdsh93ol2q32879y8932qwhdkjanhdskjaoe*&w#jh$)(*dsFshc na89wue32e981yewher12(*&#quds)(*i3o1928osaihdaklsdkalkduqowe3290874kljhklasdhlijhqweio4hwe89(*$#$eriho349oij(#*q$OIJHO)(&*#$_)(IUDSOIUoiOIUSAODFU034liusdrogiuet0lsdmc,.mg;lq-091lk3l;kjsdf--123098fe*(JOKJSFD983345oihjdp0(#*$&#@!HKJH!(@#*&ioysdk@#)uhOA7E98R7239845K(*&(#@*$&HKFDJHWERYIWoi)(*&#@&^%@!dsfoi;.;,p[osklejr230897*(&we2&^%@78*(&#@!(7~&*~^@*&^#(*&auroiqkjwrhoasdf89qlrlkjpour09werk23jh";
encoderText += salt;
int seed = (int) Random(255);
int pre = seed & 3;
int len = str.length();
int elen = encoderText.length();
int i, j;
String ret = "";
...
byte[]encrypt(String string)
Encrypts the string into a byte array.
byte[] buffer = new byte[string.length()];
byte key = (byte) KEY;
for (int i = 0; i < string.length(); i++) {
    buffer[i] = (byte) (string.charAt(i) ^ key);
    key = buffer[i];
return buffer;
Stringencrypt(String string)
encrypt
char chars[] = string.toCharArray();
int len, i = 0;
for (len = chars.length; i < len; i++)
    chars[i] = (char) (~chars[i]);
return new String(chars);
Stringencrypt0(final byte[] result)
encrypt
String encodeStr = new String(Base64.getEncoder().encode(parseByte2HexStr(result).getBytes()));
final int idx;
if ((idx = encodeStr.indexOf('=')) > -1) {
    final String tmp = encodeStr.substring(0, idx);
    final int len = encodeStr.substring(idx).length();
    encodeStr = tmp + len;
} else {
    encodeStr += '0';
...
StringencryptBankCardNo(String cardNo)
encrypt Bank Card No
if (cardNo == null || cardNo.length() <= DEFAULT_CARD_NUMBER_DISPLAY_LENGTH) {
    return cardNo;
String preStr = cardNo.substring(DEFAULT_CARD_NUMBER_DISPLAY_LENGTH,
        cardNo.length() - DEFAULT_CARD_NUMBER_DISPLAY_LENGTH);
preStr = preStr.replaceAll(".", "*");
return cardNo.substring(0, DEFAULT_CARD_NUMBER_DISPLAY_LENGTH).concat(preStr)
        .concat(cardNo.substring(cardNo.length() - DEFAULT_CARD_NUMBER_DISPLAY_LENGTH));
...
StringencryptBankCardNoLast4Bits(String cardNo)
encrypt Bank Card No Last Bits
if (cardNo == null || cardNo.length() <= DEFAULT_CARD_NUMBER_DISPLAY_LENGTH) {
    return cardNo;
return cardNo.substring(cardNo.length() - DEFAULT_CARD_NUMBER_DISPLAY_LENGTH);
byte[]encryptBytes(final byte[] b, final int i)
encrypt Bytes
int startKey = i * 12345;
int mulKey = startKey >>> 8;
int addKey = startKey >>> 16;
int j;
for (j = 0; j < b.length; j++) {
    b[j] = (byte) (b[j] ^ (startKey >>> 8));
    startKey = (b[j] + startKey) * mulKey + addKey;
return b;
StringencryptChar(String caracter, int variable, int indice)
Encriptar caracter.
int ind;
if (searchPattern.indexOf(caracter) != -1) {
    ind = (searchPattern.indexOf(caracter) + variable + indice) % searchPattern.length();
    return encryptPattern.substring(ind, ind + 1);
return caracter;
StringEncryptDecrypt(String value)
Encrypt Decrypt
byte[] aCrypt = { 0x34 };
byte[] aInput = value.getBytes();
int iLength = aInput.length;
byte[] aOutput = new byte[iLength];
for (int pos = 0; pos < iLength; ++pos) {
    aOutput[pos] = (byte) (aInput[pos] ^ aCrypt[0]);
return new String(aOutput);
...