Des decryption, but key is 36 bytes, how to handle?

Source: Internet
Author: User
Tags decrypt log log
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.