问题描述
importjava.security.Key;importjava.security.SecureRandom;importjavax.crypto.Cipher;importjavax.crypto.KeyGenerator;importsun.misc.BASE64Decoder;importsun.misc.BASE64Encoder;publicclassDes{Keykey;/***根据参数生成KEY*@paramstrKey*/publicvoidgetKey(StringstrKey){try{KeyGenerator_generator=KeyGenerator.getInstance("DES");_generator.init(newSecureRandom(strKey.getBytes()));this.key=_generator.generateKey();_generator=null;}catch(Exceptione){e.printStackTrace();}}/***加密String明文输入,String密文输出*@paramstrMingString明文*@returnString密文*/publicStringgetEncString(StringstrMing){byte[]byteMi=null;byte[]byteMing=null;StringstrMi="";BASE64Encoderbase64en=newBASE64Encoder();try{byteMing=strMing.getBytes("UTF8");byteMi=this.getEncCode(byteMing);strMi=base64en.encode(byteMi);}catch(Exceptione){e.printStackTrace();}finally{base64en=null;byteMing=null;byteMi=null;}returnstrMi;}/***解密以String密文输入,String明文输出*@paramstrMiString密文*@returnString明文*/publicStringgetDesString(StringstrMi){BASE64Decoderbase64De=newBASE64Decoder();byte[]byteMing=null;byte[]byteMi=null;StringstrMing="";try{byteMi=base64De.decodeBuffer(strMi);byteMing=this.getDesCode(byteMi);strMing=newString(byteMing,"UTF8");}catch(Exceptione){e.printStackTrace();}finally{base64De=null;byteMing=null;byteMi=null;}returnstrMing;}
解决方案
解决方案二:
BASE64Decoderbase64De=newBASE64Decoder();你用这个程序不会提示错误吗,啊而且myeclipse找不到这个api