|
|
|
สอบถาม ท่านใดเคยทำ void statement ผ่าน kbank ด้วย php บ้างครับ |
|
|
|
|
|
|
|
มี code java encypt ท่านใดพอจะแปลงเป็น php ได้บ้างครับ
Code (Java)
import java.applet.*;
public class SinaptIQ3DES extends Applet {
public void init() {
}
public static final String encrypt(String s)
{
String s1 = "";
try
{
SecretKeySpec secretkeyspec = new SecretKeySpec(new byte[] {
-101, -66, -84, -119, -56, 52, -7, -15, -76, -87,
-26, 45, 95, 82, 50, -113, 75, -102, 110, -46,
-11, 37, 35, -8
}, "DESede");
IvParameterSpec ivparameterspec = new IvParameterSpec(new byte[] {
-15, -19, 8, 64, -24, 47, -13, -73
});
Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
cipher.init(1, secretkeyspec, ivparameterspec);
Date date = new Date();
SimpleDateFormat simpledateformat = new SimpleDateFormat("SSSssmmHHddMMyyyy");
SimpleDateFormat simpledateformat1 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String s2 = (new StringBuilder()).append(simpledateformat.format(date)).append(s).append(simpledateformat1.format(date)).toString();
byte abyte0[] = s2.getBytes();
byte abyte1[] = cipher.doFinal(abyte0);
s1 = b64Encode(abyte1);
cipher = null;
}
catch(Exception exception)
{
s1 = exception.getMessage();
}
return s1;
}
public static final String decrypt(String encrypted) {
String result = "";
try {
javax.crypto.SecretKey key = new javax.crypto.spec.SecretKeySpec(
new byte[]
{(byte)0x9b, (byte)0xbe, (byte)0xac, (byte)0x89,
(byte)0xc8, (byte)0x34, (byte)0xf9, (byte)0xf1,
(byte)0xb4, (byte)0xa9, (byte)0xe6, (byte)0x2d,
(byte)0x5f, (byte)0x52, (byte)0x32, (byte)0x8f,
(byte)0x4b, (byte)0x9a, (byte)0x6e, (byte)0xd2,
(byte)0xf5, (byte)0x25, (byte)0x23, (byte)0xf8}, "DESede");
javax.crypto.spec.IvParameterSpec iv = new javax.crypto.spec.IvParameterSpec(
new byte[]
{(byte)0xf1, (byte)0xed, (byte)0x08, (byte)0x40,
(byte)0xe8, (byte)0x2f, (byte)0xf3, (byte)0xb7});
javax.crypto.Cipher tDes = javax.crypto.Cipher.getInstance("DESede/CBC/PKCS5Padding");
tDes.init(javax.crypto.Cipher.DECRYPT_MODE, key, iv);
byte[] encryptedB = b64Decode(encrypted);
byte[] decrypted = tDes.doFinal(encryptedB);
result = new String(decrypted);
result = result.substring(17, result.length()-17);
tDes = null;
} catch (Exception e) {
result = e.getMessage();
}
return result;
}
private static char[] map1 = new char[64];
static {
int i=0;
for (char c='A'; c<='Z'; c++) map1[i++] = c;
for (char c='a'; c<='z'; c++) map1[i++] = c;
for (char c='0'; c<='9'; c++) map1[i++] = c;
map1[i++] = '+'; map1[i++] = '/';
}
private static byte[] map2 = new byte[128];
static {
for (int i=0; i<map2.length; i++) map2[i] = -1;
for (int i=0; i<64; i++) map2[map1[i]] = (byte)i;
}
private static String b64Encode(byte[] in) {
int iLen = in.length;
int oDataLen = (iLen*4+2)/3;
int oLen = ((iLen+2)/3)*4;
char[] out = new char[oLen];
int ip = 0;
int op = 0;
while (ip < iLen) {
int i0 = in[ip++] & 0xff;
int i1 = ip < iLen ? in[ip++] & 0xff : 0;
int i2 = ip < iLen ? in[ip++] & 0xff : 0;
int o0 = i0 >>> 2;
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
int o3 = i2 & 0x3F;
out[op++] = map1[o0];
out[op++] = map1[o1];
out[op] = op < oDataLen ? map1[o2] : '='; op++;
out[op] = op < oDataLen ? map1[o3] : '='; op++; }
return new String(out);
}
private static byte[] b64Decode(String str) {
char[] in = str.toCharArray();
int iLen = in.length;
if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
while (iLen > 0 && in[iLen-1] == '=') iLen--;
int oLen = (iLen*3) / 4;
byte[] out = new byte[oLen];
int ip = 0;
int op = 0;
while (ip < iLen) {
int i0 = in[ip++];
int i1 = in[ip++];
int i2 = ip < iLen ? in[ip++] : 'A';
int i3 = ip < iLen ? in[ip++] : 'A';
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
int b0 = map2[i0];
int b1 = map2[i1];
int b2 = map2[i2];
int b3 = map2[i3];
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
int o0 = ( b0 <<2) | (b1>>>4);
int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
int o2 = ((b2 & 3)<<6) | b3;
out[op++] = (byte)o0;
if (op<oLen) out[op++] = (byte)o1;
if (op<oLen) out[op++] = (byte)o2; }
return out;
}
}
ขอคำแนะนำด้วยครับ หรือมีวิธีอื่นก็สามารถแนะนำได้ครับ ใช้ php
Tag : PHP, jQuery, CakePHP, JAVA, Linux
|
|
|
|
|
|
Date :
2015-02-14 11:35:02 |
By :
wonderland |
View :
731 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2015-02-15 07:20:53 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|