11
zhouwei
2019-07-12 143f7be25ff19896e70ffc486999a64a3bc3b76f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.safeluck.aaej.app.utils;
 
import org.apache.commons.codec.binary.Base64;
 
import java.io.UnsupportedEncodingException;
 
/**
 * Created by zhouwei on 2015/11/23.
 */
public class PayMessageEncryptor  {
 
    public String decrypt(byte[] bytes){
 
        Base64 b64 =new Base64();
 
        byte[] b64_bytes = b64.decode(bytes);
 
        data_encrypt(b64_bytes,0,b64_bytes.length);
        try {
            return new String(b64_bytes,"utf-8") ;
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
 
    public String encrypt(byte[] data) {
        data_encrypt(data, 0, data.length);
        Base64 b64 =new Base64();
        return b64.encodeAsString(data);
    }
 
    static int p_IA1 = 0x2DA12EE;
    static int p_IC1 = 0x013A85F;
    static int M_Key = 0x5345A75;
    static int ID_Key = 0x2EA901A;
 
    public void data_encrypt(byte[] buffer, int idx, int size)
    {
        int Key_0, ID_0;
 
        if (M_Key == 0)
            Key_0 = 1;
        else
            Key_0 = M_Key;
 
        if (ID_Key == 0)
            ID_0 = 1;
        else
            ID_0 = ID_Key;
 
        while (idx < size)
        {
            Key_0 = p_IA1 * (Key_0 % ID_0) + p_IC1;
            buffer[idx++] ^= ((Key_0 >> 15) + 0xe3) & 0xFF;
        }
    }
}