问题描述
我现在有一个java实现的DES加密解密算法,现在我想用C来实现互换,也即用java加密的C可以解密,C加密的java可以解密,谁帮帮我?谢谢了。java实现的DES算法如下:/***用DES方法加密输入的字节*bytKey需为8字节长,是加密的密码*/privatebyte[]encryptByDES(byte[]bytP,byte[]bytKey){byte[]result=null;try{DESKeySpecdesKS=newDESKeySpec(bytKey);SecretKeyFactoryskf=SecretKeyFactory.getInstance("DES");SecretKeysk=skf.generateSecret(desKS);Ciphercip=Cipher.getInstance("DES");cip.init(Cipher.ENCRYPT_MODE,sk);result=cip.doFinal(bytP);}catch(Exceptionex){System.err.println("DESOperator.encryptByDES():"+ex.getMessage());}returnresult;}/***用DES方法解密输入的字节*bytKey需为8字节长,是解密的密码*/privatebyte[]decryptByDES(byte[]bytE,byte[]bytKey){byte[]result=null;try{DESKeySpecdesKS=newDESKeySpec(bytKey);SecretKeyFactoryskf=SecretKeyFactory.getInstance("DES");SecretKeysk=skf.generateSecret(desKS);Ciphercip=Cipher.getInstance("DES");cip.init(Cipher.DECRYPT_MODE,sk);result=cip.doFinal(bytE);}catch(Exceptionex){System.err.println("DESOperator.decryptByDES():"+ex.getMessage());}returnresult;}
解决方案
解决方案二:
对了,谁有对应的C的算法,麻烦发到我邮箱,谢谢了,指望好人了。sunstar_li@163.com