//
|
// Source code recreated from a .class file by IntelliJ IDEA
|
// (powered by Fernflower decompiler)
|
//
|
|
package com.product.data.sync.service.media;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.UnsupportedEncodingException;
|
|
public class Encryption {
|
private int intPrivateKey = 0;
|
private static final long MaxInt = (long)Math.pow(2.0D, 32.0D);
|
private int[] intConstKey = new int[]{1556696929, 1266038903, 1265722019, 1265722531, 1265658509, 1265282947, 1263528397, 1263599759, 1263487033, 1263648241, 1262235517, 1262210177, 1261371079, 1261525493, 1261118363, 1260675071, 1260706169, 1260299731, 1260230359, 1259026997, 1258887283, 1258865891, 1258626371, 1258503781, 1258482227, 1258579643, 1258190971, 1258098757, 1257611279, 1257724121, 1257273319, 1257361279, 1256913187, 1256892151, 1256455111, 1256408429, 1060988843, 1028046497, 1059548141, 1059702103, 1059282011, 1057910353, 1057261279, 1056410731, 1027302959, 1056241757, 1053532217, 1053109769, 1052145631, 1052156549, 1052311109, 1052138359, 1051307749, 1051455023, 1030905121, 1030546703, 1030613851, 1030517641, 1029296581, 1029412469, 1028968387, 1028847733, 1028118731, 1028044769};
|
private int[] intUserKey = new int[64];
|
private int[] intPosition = new int[64];
|
private static int encryptionInfo = 3;
|
private static long readTimer = 0L;
|
public static final long lngREMAINTIMER = 600000L;
|
public static final long abc = Long.parseLong("7776000000");
|
|
public Encryption(String strKey) {
|
int[] intData = this.getStringLong(strKey);
|
this.intPrivateKey = 0;
|
int i;
|
if (intData != null) {
|
for(i = 0; i < intData.length; ++i) {
|
this.intPrivateKey ^= intData[i];
|
}
|
}
|
|
intData = this.getStringLong(String.valueOf(this.intPrivateKey));
|
|
for(i = 0; i < intData.length; ++i) {
|
this.intPrivateKey ^= intData[i];
|
}
|
|
this.processKeyGene();
|
}
|
|
public Encryption() {
|
}
|
|
public int[] getStringLong(String strString) {
|
byte[] byteString = strString.getBytes();
|
int intI = 0;
|
int intIndex = -1;
|
if (byteString.length == 0) {
|
return null;
|
} else {
|
int[] intData;
|
int intByte;
|
for(intData = new int[(byteString.length - 1) / 4 + 1]; intI < byteString.length; intData[intIndex] = (intData[intIndex] << 8) + intByte) {
|
if (intI % 4 == 0) {
|
++intIndex;
|
intData[intIndex] = 0;
|
}
|
|
intByte = byteString[intI++];
|
if (intByte < 0) {
|
intByte += 256;
|
}
|
}
|
|
return intData;
|
}
|
}
|
|
public String getLongString(int[] intData) {
|
String strData = "";
|
if (intData != null) {
|
int[] intLocation = new int[]{-16777216, 16711680, 65280, 255};
|
int[] intMove = new int[]{24, 16, 8, 0};
|
int intIndex = 0;
|
int intI = 0;
|
int intLen = (intData.length - 1) * 4 + 1;
|
int tmp = intData[intData.length - 1];
|
if (tmp < 0) {
|
intLen += 3;
|
} else {
|
while(tmp > 255) {
|
++intLen;
|
tmp >>= 8;
|
}
|
}
|
|
byte[] bytString = new byte[intLen];
|
intLen = 0;
|
|
while(intI < intData.length - 1) {
|
bytString[intLen++] = (byte)((intData[intI] & intLocation[intIndex]) >> intMove[intIndex]);
|
++intIndex;
|
if (intIndex > 3) {
|
++intI;
|
intIndex = 0;
|
}
|
}
|
|
tmp = intData[intData.length - 1];
|
|
for(intI = bytString.length - 1; intI >= intLen; --intI) {
|
bytString[intI] = (byte)(tmp & 255);
|
tmp >>= 8;
|
}
|
try {
|
//默认工作空间字符集
|
strData = new String(bytString,"GBK");
|
} catch (UnsupportedEncodingException e) {
|
e.printStackTrace();
|
}
|
}
|
|
return strData;
|
}
|
|
public int[] getHexLong(String strHex) {
|
if (strHex.length() == 0) {
|
return null;
|
} else {
|
int[] intData = new int[(strHex.length() - 1) / 8 + 1];
|
String strSubHex = "";
|
|
for(int i = 0; i < strHex.length(); i += 8) {
|
if (i + 8 < strHex.length()) {
|
strSubHex = strHex.substring(i, i + 8);
|
} else {
|
strSubHex = strHex.substring(i);
|
}
|
|
intData[i / 8] = (int)Long.parseLong(strSubHex, 16);
|
}
|
|
return intData;
|
}
|
}
|
|
public String getLongHex(int[] intData) {
|
String strHex = "";
|
String strSubHex = "";
|
if (intData != null) {
|
for(int i = 0; i < intData.length - 1; ++i) {
|
strSubHex = Integer.toHexString(intData[i]).toUpperCase();
|
|
for(int j = strSubHex.length(); j < 8; ++j) {
|
strSubHex = "0" + strSubHex;
|
}
|
|
strHex = strHex + strSubHex;
|
}
|
|
strSubHex = Integer.toHexString(intData[intData.length - 1]).toUpperCase();
|
if (strSubHex.length() % 2 != 0) {
|
strSubHex = "0" + strSubHex;
|
}
|
|
strHex = strHex + strSubHex;
|
}
|
|
return strHex;
|
}
|
|
private void processKeyGene() {
|
boolean[] blnInGene = new boolean[64];
|
int intGCount = -1;
|
int[] intGene = new int[64];
|
String strPrivateKey = String.valueOf(this.intPrivateKey);
|
|
int i;
|
for(i = 0; i < 64; ++i) {
|
this.intUserKey[i] = this.intConstKey[i];
|
blnInGene[i] = false;
|
this.intPosition[i] = i;
|
intGene[i] = -1;
|
}
|
|
int intG;
|
for(i = 0; i < strPrivateKey.length(); ++i) {
|
if (strPrivateKey.substring(i, i + 1).equals("-")) {
|
intG = 0;
|
} else {
|
intG = Integer.parseInt(strPrivateKey.substring(i, i + 1));
|
}
|
|
if (!blnInGene[intG]) {
|
blnInGene[intG] = true;
|
this.intPrivateKey ^= this.intUserKey[intG];
|
++intGCount;
|
intGene[intGCount] = intG;
|
}
|
}
|
|
int intCount = intGCount;
|
|
int j;
|
for(i = 0; i <= intCount; ++i) {
|
if (intGene[i] > 0 && intGene[i] < 7) {
|
for(j = 0; j <= intCount; ++j) {
|
intG = intGene[i] * 10 + intGene[j];
|
if (intG < 64 && !blnInGene[intG]) {
|
++intGCount;
|
intGene[intGCount] = intG;
|
this.intPrivateKey ^= this.intUserKey[intG];
|
}
|
}
|
}
|
}
|
|
++intGCount;
|
|
for(i = 0; i < 64; ++i) {
|
j = (int)((double)intGene[i % intGCount] * Math.pow((double)i, 2.0D)) & 31;
|
intG = this.intUserKey[i];
|
this.intUserKey[i] = this.intUserKey[j];
|
this.intUserKey[j] = intG;
|
intG = this.intPosition[i];
|
this.intPosition[i] = this.intPosition[j];
|
this.intPosition[j] = intG;
|
}
|
|
}
|
|
public String encryptString(String strString, boolean blnGetHex) {
|
if (EncrypUtil.isFingerprint(strString)) {
|
return EncrypUtil.getFingerValue(strString);
|
} else {
|
return blnGetHex ? this.getLongHex(this.encryptData(this.getStringLong(strString), true)) : this.getLongString(this.encryptData(this.getStringLong(strString), true));
|
}
|
}
|
|
public String encryptString(String strString) {
|
return this.getLongString(this.encryptData(this.getStringLong(strString), true));
|
}
|
|
public String decryptionString(String strString, boolean blnIsHex) {
|
return blnIsHex ? this.getLongString(this.encryptData(this.getHexLong(strString), false)) : this.getLongString(this.encryptData(this.getStringLong(strString), false));
|
}
|
|
public String decryptionString(String strString) {
|
return this.getLongString(this.encryptData(this.getStringLong(strString), false));
|
}
|
|
public int[] encryptData(int[] intData, boolean blnEncryption) {
|
if (intData == null) {
|
return null;
|
} else {
|
int intLen = intData.length;
|
int[] intEncryptData = new int[intLen];
|
int[] intModPosition = (int[])null;
|
int intMod = intLen & 63;
|
int i;
|
int j;
|
if (intMod > 0) {
|
intModPosition = new int[intMod];
|
i = -1;
|
|
for(j = 0; j < 64; ++j) {
|
if (this.intPosition[j] < intMod) {
|
++i;
|
intModPosition[i] = this.intPosition[j];
|
}
|
}
|
}
|
|
if (blnEncryption) {
|
for(i = 0; i < intLen; ++i) {
|
if (intLen - i > 63) {
|
for(j = 0; j < 64; ++j) {
|
intEncryptData[i + j] = intData[i + this.intPosition[j]] ^ this.intPrivateKey ^ this.intUserKey[j];
|
}
|
|
i += 63;
|
} else {
|
for(j = 0; j < intLen - i; ++j) {
|
intEncryptData[i + j] = intData[i + intModPosition[j]] ^ this.intPrivateKey ^ this.intUserKey[j];
|
}
|
|
i = intLen;
|
}
|
}
|
} else {
|
for(i = 0; i < intData.length; ++i) {
|
if (intLen - i > 63) {
|
for(j = 0; j < 64; ++j) {
|
intEncryptData[i + this.intPosition[j]] = intData[i + j] ^ this.intPrivateKey ^ this.intUserKey[j];
|
}
|
|
i += 63;
|
} else {
|
for(j = 0; j < intLen - i; ++j) {
|
intEncryptData[i + intModPosition[j]] = intData[i + j] ^ this.intPrivateKey ^ this.intUserKey[j];
|
}
|
|
i = intLen;
|
}
|
}
|
}
|
|
return intEncryptData;
|
}
|
}
|
|
public static int getEncryptionMachineInfo() {
|
return encryptionInfo;
|
}
|
|
public byte[] decryptionFile(String strFileName) {
|
byte[] bytData = (byte[])null;
|
File file = new File(strFileName);
|
int fleLen = (int)file.length();
|
if (fleLen > 8) {
|
try {
|
FileInputStream in = new FileInputStream(file);
|
int srcLength = 0;
|
bytData = new byte[4];
|
|
int intIndex;
|
for(int i = 0; i < 2; ++i) {
|
in.read(bytData);
|
|
for(intIndex = 3; intIndex >= 0; --intIndex) {
|
if (bytData[intIndex] < 0) {
|
srcLength = (srcLength << 8) + 256 + bytData[intIndex];
|
} else {
|
srcLength = (srcLength << 8) + bytData[intIndex];
|
}
|
}
|
}
|
|
fleLen -= 8;
|
bytData = new byte[fleLen];
|
in.read(bytData);
|
in.close();
|
if (fleLen % 4 == 0) {
|
fleLen /= 4;
|
} else {
|
fleLen = fleLen / 4 + 1;
|
}
|
|
int[] intData = new int[fleLen];
|
intIndex = 0;
|
|
int i;
|
for(i = 0; i < fleLen; ++i) {
|
intIndex += 4;
|
|
for(int j = 1; j < 5; ++j) {
|
int index = intIndex - j;
|
if (index < bytData.length) {
|
if (bytData[index] < 0) {
|
intData[i] = (intData[i] << 8) + 256 + bytData[index];
|
} else {
|
intData[i] = (intData[i] << 8) + bytData[index];
|
}
|
}
|
}
|
}
|
|
intData = this.encryptData(intData, false);
|
bytData = new byte[srcLength];
|
intIndex = 0;
|
|
for(i = 0; i < fleLen; ++i) {
|
long lngData = intData[i] < 0 ? MaxInt + (long)intData[i] : (long)intData[i];
|
intIndex += 4;
|
|
for(int j = 4; j > 0; --j) {
|
int index = intIndex - j;
|
if (index < srcLength) {
|
bytData[intIndex - j] = (byte)((int)(lngData & 255L));
|
lngData >>= 8;
|
}
|
}
|
}
|
} catch (Exception var14) {
|
var14.printStackTrace();
|
}
|
}
|
|
return bytData;
|
}
|
|
public static void main(String[] args) {
|
Encryption en = new Encryption("199678B2");
|
System.out.print(en.encryptString("199678B2", true));
|
}
|
}
|