如何将以下加密代码转换为js?

时间:2019-09-16 12:03:13

标签: javascript java encryption

我不知道如何在js中使用getByte()以及如何使用CryptoJS进行加密。

我反编译程序并获得用于加密算法的程序。我必须将其转换为js。由于Java中存在getByted(),我不知道如何在js中处理此功能。

生成desede的密码必须使用getByte(),这使我非常恼火。如果可以将此密码更改为正确的字符串,我想我可以解决此问题。

//function m2866a,a program for generating a password 
//function m2865a,a encrypted program.
public static String m2865a(byte[] bArr, byte[] bArr2) {
        try {
            if (bArr.length == 16) { // short key ? .. extend to 24 byte key
                byte[] tmpKey = new byte[24];
                System.arraycopy(bArr, 0, tmpKey, 0, 16);
                System.arraycopy(bArr, 0, tmpKey, 16, 8);
                bArr = tmpKey;
            }
            for (byte i : bArr) {
                System.out.print(i+",");
            }
            System.out.println();
            SecretKeySpec secretKeySpec = new SecretKeySpec(bArr, "DESede");
            Cipher instance = Cipher.getInstance("DESede/ECB/NoPadding");
            instance.init(1, secretKeySpec);
            return m2864a(instance.doFinal(m2869b(bArr2)));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e2) {
            e2.printStackTrace();
        } catch (NoSuchPaddingException e3) {
            e3.printStackTrace();
        } catch (BadPaddingException e4) {
            e4.printStackTrace();
        } catch (IllegalBlockSizeException e5) {
            e5.printStackTrace();
        }
        return null;
    }
public static byte[] m2866a(int i, int i2) {
        byte[] bArr = new byte[16];
        bArr[0] = (byte) (i2 & 255);
        bArr[1] = (byte) (i & 255);
        bArr[2] = (byte) ((i >> 8) & 255);
        bArr[3] = 0;
        for (int i3 = 4; i3 < 8; i3++) {
            bArr[i3] = (byte) (bArr[i3 - 4] ^ -1);
        }
        for (int i4 = 8; i4 < 12; i4++) {
            bArr[i4] = (byte) (bArr[i4 - 8] ^ bArr[(bArr.length - i4) - 1]);
        }
        bArr[12] = (byte) (bArr[8] ^ 161);
        bArr[13] = (byte) (bArr[9] ^ 27);
        bArr[14] = (byte) (bArr[10] ^ 193);
        bArr[15] = (byte) (bArr[11] ^ 29);
        return bArr;
    }
private static byte[] m2869b(byte[] bArr) {
        int length = 8 - (bArr.length % 8);
        byte[] bArr2 = new byte[(bArr.length + length)];
        System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
        for (int i = 0; i < length; i++) {
            bArr2[bArr.length + i] = 0;
        }
        return bArr2;
    }
public static void main(String[] args) throws UnsupportedEncodingException {
        String CustomerID = "15";
        String AgentID = "37";
        String AccNum = "22194";
        String CardID = "2615021229";
        String AccName = "中文";
        String PerCode = "12345678";
        String OrderNumb = "12414255";
        String RandomNum = "116685";
        byte[] temp = C0646f.m2866a(Integer.parseInt(CustomerID), Integer.parseInt(AgentID));
        String a = C0646f.m2865a(
                C0646f.m2866a(Integer.parseInt(CustomerID), Integer.parseInt(AgentID)),
                ("1,1," + AgentID + "," + CustomerID + "," + AccNum + "," + CardID + "," + AccName + "," + PerCode + ","
                        + OrderNumb + "," + RandomNum).getBytes("GB2312")
        );
        System.out.println(a);
    }

0 个答案:

没有答案