des的求一个加密算法!!!! des .net siteserver加密密码.netphp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 找个des工具算算加密结果,不相同的话,只能问原开发人员 不是呀!我测了一下!加密,解密类:package com.baobaotao.placeholder;import java.security.Key;import java.security.SecureRandom;import javax.crypto.Cipher;import javax.crypto.KeyGenerator;import sun.misc.BASE64Decoder;import sun.misc.BASE64Encoder;public class DESUtils { private static Key key; private static String KEY_STR = "sPqql2LKNhKIdtu/yGlt8g=="; static { try { KeyGenerator generator = KeyGenerator.getInstance("DES"); generator.init(new SecureRandom(KEY_STR.getBytes())); key = generator.generateKey(); generator = null; } catch (Exception e) { throw new RuntimeException(e); } } /** * 对str进行DES加密 * * @param str * @return */ public static String getEncryptString(String str) { BASE64Encoder base64en = new BASE64Encoder(); try { byte[] strBytes = str.getBytes("UTF8"); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptStrBytes = cipher.doFinal(strBytes); return base64en.encode(encryptStrBytes); } catch (Exception e) { throw new RuntimeException(e); } } /** * 对str进行DES解密 * * @param str * @return */ public static String getDecryptString(String str) { BASE64Decoder base64De = new BASE64Decoder(); try { byte[] strBytes = base64De.decodeBuffer(str); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decryptStrBytes = cipher.doFinal(strBytes); return new String(decryptStrBytes, "UTF8"); } catch (Exception e) { throw new RuntimeException(e); } } public static void main(String[] args) throws Exception {// if (args == null || args.length < 1) {// System.out.println("请输入要加密的字符,用空格分隔.");// } else {// for (String arg : args) {// System.out.println(arg + ":" + getEncryptString(arg));// }// } System.out.println(getDecryptString("WnplV/ietfQ=")); System.out.println(getDecryptString("gJQ9O+q34qk=")); }}Test类:package com.baobaotao.placeholder;import java.util.*;public class Test { public static void main(String[] args){ String str,str1; Scanner input=new Scanner(System.in); str=input.nextLine(); str1=DESUtils.getEncryptString(str); System.out.println(str1); }} 使用AJAX具体步骤 准备着手写一个公交路线查询 rewrite配置及编写规则 google统计报表出错 wordpress 2.7中的文本编辑器在哪个php文件中~~~急。。。。。高分!!!!! php混淆解密 谁能帮我下?顺便教我方法 关于cakephp的画面跳转的问题 网站经常爆FastCGI Error的错误?麻烦大牛进来看看 求在杭州的 php大神,做的是织梦后台,遇到问题,希望可以得到解决. ModPHP 应用程序框架开源送上,为 CMS 而生,可做 PHP 扩展 还是php的概率的问题,求解说 有没有php cs的相关编程例子
加密,解密类:
package com.baobaotao.placeholder;import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;public class DESUtils {
private static Key key;
private static String KEY_STR = "sPqql2LKNhKIdtu/yGlt8g==";
static {
try {
KeyGenerator generator = KeyGenerator.getInstance("DES");
generator.init(new SecureRandom(KEY_STR.getBytes()));
key = generator.generateKey();
generator = null;
} catch (Exception e) {
throw new RuntimeException(e);
}
} /**
* 对str进行DES加密
*
* @param str
* @return
*/
public static String getEncryptString(String str) {
BASE64Encoder base64en = new BASE64Encoder();
try {
byte[] strBytes = str.getBytes("UTF8");
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptStrBytes = cipher.doFinal(strBytes);
return base64en.encode(encryptStrBytes);
} catch (Exception e) {
throw new RuntimeException(e);
}
} /**
* 对str进行DES解密
*
* @param str
* @return
*/
public static String getDecryptString(String str) {
BASE64Decoder base64De = new BASE64Decoder();
try {
byte[] strBytes = base64De.decodeBuffer(str);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decryptStrBytes = cipher.doFinal(strBytes);
return new String(decryptStrBytes, "UTF8");
} catch (Exception e) {
throw new RuntimeException(e);
} } public static void main(String[] args) throws Exception {
// if (args == null || args.length < 1) {
// System.out.println("请输入要加密的字符,用空格分隔.");
// } else {
// for (String arg : args) {
// System.out.println(arg + ":" + getEncryptString(arg));
// }
// }
System.out.println(getDecryptString("WnplV/ietfQ="));
System.out.println(getDecryptString("gJQ9O+q34qk="));
}
}Test类:
package com.baobaotao.placeholder;import java.util.*;
public class Test {
public static void main(String[] args){
String str,str1;
Scanner input=new Scanner(System.in);
str=input.nextLine();
str1=DESUtils.getEncryptString(str);
System.out.println(str1);
}}