java php DES 加密解密
import java.io.IOException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DES {
private byte[] desKey;
public DES(String desKey) {
this.desKey = desKey.getBytes();
}
public byte[] desEncrypt(byte[] plainText) throws Exception {
SecureRandom sr = new SecureRandom();
byte rawKeyData[] = desKey;
DESKeySpec dks = new DESKeySpec(rawKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key, sr);
byte data[] = plainText;
byte encryptedData[] = cipher.doFinal(data);
return encryptedData;
}
public byte[] desDecrypt(byte[] encryptText) throws Exception {
SecureRandom sr = new SecureRandom();
byte rawKeyData[] = desKey;
DESKeySpec dks = new DESKeySpec(rawKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key, sr);
byte encryptedData[] = encryptText;
byte decryptedData[] = cipher.doFinal(encryptedData);
return decryptedData;
}
public String encrypt(String input) throws Exception {
return base64Encode(desEncrypt(input.getBytes()));
}
public String decrypt(String input) throws Exception {
byte[] result = base64Decode(input);
return new String(desDecrypt(result));
}
public static String base64Encode(byte[] s) {
if (s == null)
return null;
BASE64Encoder b = new sun.misc.BASE64Encoder();
return b.encode(s);
}
public static byte[] base64Decode(String s) throws IOException {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = decoder.de
相关文档:
老
师让下载安装jdk1.4、jdk1.5和jdk1.6三个版本的Java开发包,并且熟练切换各个环境,其实就是配置不同的环境变量。以前只是在环境变
量中设置了用户变量,Java运行也很正常。一旦需要在几个版本中切换,用户变量就失效了。经过尝试才知道必须设置系统变量,为了方便可以设置
JAVA_HOME变量为jdk的安装路径,再把 %JA ......
ed2k://|file|[ReadFree]_C#.开发人员指南——ASP_NET、XML、web服务与.ADO_NET_11030729.rar|6563070|B1CBF4D0032C8D78FB10F5F2AE6C3882|/
ed2k://|file|[ReadFree]_C#网络应用编程_11041620.rar|8063056|7044A65903D86BF88BE8AF26D8E02B61|/
ed2k://|file|[ReadFree]_Java.P2P程序设计_11052086.rar|8742852| ......
我对问题的理解:面试中的一个问题,居然想了半天没有什么头绪,我想还是没有思考,没有积累过。其实完全可以说上一些小细节,比如用StringBuffer代替String,用HashMap代替Hashtable, 乘法操作用位移,尽量复用已有的经过检验的高效代码等等。
下面的文章转载自别的网站,写得很专业,周到, ......
Java中调用C/C++生成的DLL
一、 生成C的头文件
1. 编辑Main.java
public class Main
{
public native static int getStrNum(byte str[], int strLen);
}
2. 生成头文件
按win + r打开“运行”窗口,输入“cmd”,打开 ......