您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

DES解密,但是key是36字节的,怎么处理?

2024/6/11 8:40:43发布17次查看
和java端进行对接的,我用php解密,key是36字节的,所以没有头绪了。我想着是不是有把这36字节转化成16或者32字节的通用方法?先谢谢大家了。
下面是java的代码片段:
public static string des_key=36位的key;

执行方法:
desutil.decrypt(rs.getstring(i+1),global.des_key );

类:
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 securerandom(); 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 sr = 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 src * @return */ public static string bytesto16hexstring(byte[] src) { stringbuilder stringbuilder = new stringbuilder(); if (src == null || src.length

回复内容: 和java端进行对接的,我用php解密,key是36字节的,所以没有头绪了。我想着是不是有把这36字节转化成16或者32字节的通用方法?先谢谢大家了。
下面是java的代码片段:
public static string des_key=36位的key;

执行方法:
desutil.decrypt(rs.getstring(i+1),global.des_key );

类:
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 securerandom(); 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 sr = 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 src * @return */ public static string bytesto16hexstring(byte[] src) { stringbuilder stringbuilder = new stringbuilder(); if (src == null || src.length

用冗余字符补全到48字节。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product