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;
|
}
|
}
|
}
|