And the Java side of the docking, I use PHP decryption, key is 36 bytes, so there is no clue. I wonder if there's a generic way to convert these 36 bytes into 16 or 32 bytes? Thank you all first.
Here is the code snippet for Java:
public static String DES_KEY="36位的key";
Execution method:
DesUtil.decrypt(rs.getString(i+1),Global.DES_KEY );
Class:
public class Desutil {private final static String des = "des"; Private final static String padding= "Des/ecb/pkcs5padding"; Private final static Log log= logfactory.getlog (desutil.class); public static byte[] Encrypt (byte[] src, byte[] key) throws Exception {securerandom sr = new Secureran Dom (); Deskeyspec DKs = new Deskeyspec (key); Secretkeyfactory keyfactory = secretkeyfactory.getinstance (DES); Secretkey SecureKey = Keyfactory.generatesecret (DKS); Cipher Cipher = cipher.getinstance (PADDING); Cipher.init (Cipher.encrypt_mode, SecureKey, SR); return cipher.dofinal (SRC); } public static byte[] Decrypt (byte[] src, byte[] key) throws Exception {SecureRandom s R = new SecureRandom (); Deskeyspec DKs = new Deskeyspec (key); Secretkeyfactory keyfactory = secretkeyfactory.getinstance (DES); Secretkey SecureKey = Keyfactory.generatesecret (DKS); Cipher Cipher = cipher.getinstance (PADDING); Cipher.init (Cipher.decrypt_mode, SecureKey, SR); return cipher.dofinal (SRC); Public final static string decrypt (string data,string key) {try { return new String (Decrypt (Base64.decode (Data.getbytes ()), key.getbytes ()); }catch (Exception e) {log.error ("Exception-->desutil"); E.printstacktrace (); } return null; Public final static string decrypt (string data,string key, String charset) {try { return new String (Decrypt (Base64.decode (Data.getbytes ()), Key.getbyTES ()), CharSet); }catch (Exception e) {log.error ("Exception-->desutil"); E.printstacktrace (); } return null; Public final static string encrypt (String code,string key) {try {return Base64.encodebytes (Encrypt (code.getbytes ("Utf-8"), Key.getbytes ()); }catch (Exception e) {log.error ("Exception-->desutil"); E.printstacktrace (); } return null; }/* public static void Main (string[] args) {/** * Convert byte[] String * * @param sr c * @return */public static String bytesto16hexstring (byte[] src) {stringbuild Er stringBuilder = new StringBuilder (""); if (src = = NULL | | src.length <= 0) {REturn ""; } for (int i = 0; i < src.length; i++) {int v = src[i] & 0xFF; String HV = integer.tohexstring (v); if (Hv.length () < 2) {stringbuilder.append (0); } stringbuilder.append (HV); } return stringbuilder.tostring (); }}
Reply content:
And the Java side of the docking, I use PHP decryption, key is 36 bytes, so there is no clue. I wonder if there's a generic way to convert these 36 bytes into 16 or 32 bytes? Thank you all first.
Here is the code snippet for Java:
public static String DES_KEY="36位的key";
Execution method:
DesUtil.decrypt(rs.getString(i+1),Global.DES_KEY );
Class:
public class Desutil {private final static String des = "des"; Private final static String padding= "Des/ecb/pkcs5padding"; Private final static Log log= logfactory.getlog (desutil.class); public static byte[] Encrypt (byte[] src, byte[] key) throws Exception {securerandom sr = new Secureran Dom (); Deskeyspec DKs = new Deskeyspec (key); Secretkeyfactory keyfactory = secretkeyfactory.getinstance (DES); Secretkey SecureKey = Keyfactory.generatesecret (DKS); Cipher Cipher = cipher.getinstance (PADDING); Cipher.init (Cipher.encrypt_mode, SecureKey, SR); return cipher.dofinal (SRC); } public static byte[] Decrypt (byte[] src, byte[] key) throws Exception {SecureRandom s R = new SecureRandom (); Deskeyspec DKs = new Deskeyspec (key); Secretkeyfactory keyfactory = secretkeyfactory.getinstance (DES); Secretkey SecureKey = Keyfactory.generatesecret (DKS); Cipher Cipher = cipher.getinstance (PADDING); Cipher.init (Cipher.decrypt_mode, SecureKey, SR); return cipher.dofinal (SRC); Public final static string decrypt (string data,string key) {try { return new String (Decrypt (Base64.decode (Data.getbytes ()), key.getbytes ()); }catch (Exception e) {log.error ("Exception-->desutil"); E.printstacktrace (); } return null; Public final static string decrypt (string data,string key, String charset) {try { return new String (Decrypt (Base64.decode (Data.getbytes ()), Key.getbyTES ()), CharSet); }catch (Exception e) {log.error ("Exception-->desutil"); E.printstacktrace (); } return null; Public final static string encrypt (String code,string key) {try {return Base64.encodebytes (Encrypt (code.getbytes ("Utf-8"), Key.getbytes ()); }catch (Exception e) {log.error ("Exception-->desutil"); E.printstacktrace (); } return null; }/* public static void Main (string[] args) {/** * Convert byte[] String * * @param sr c * @return */public static String bytesto16hexstring (byte[] src) {stringbuild Er stringBuilder = new StringBuilder (""); if (src = = NULL | | src.length <= 0) {REturn ""; } for (int i = 0; i < src.length; i++) {int v = src[i] & 0xFF; String HV = integer.tohexstring (v); if (Hv.length () < 2) {stringbuilder.append (0); } stringbuilder.append (HV); } return stringbuilder.tostring (); }}
Complete up to 48 bytes with redundant characters.