易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

通过java反射机制动态调用某方法的总结

通过java的反射机制,动态调用某个方法:
如下:
public Object invokeMethod(String className, String methodName,
Object[] args) throws Exception{
Class ownerClass = Class.forName(className);
Object owner = ownerClass.newInstance();

Class[] argsClass = new Class[args.length ......

JAVA将内容追加到文件尾部

import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
 * 将内容追加到文件尾部
 */
public class AppendToFile
{
    /**
     * A方法追加文件:使用RandomAccessFile
     *
    ......

java性能的优化(三)

    关于线程的操作,要注意如下几个方面。
    (1) 防止过多的同步
   
如上所示,不必要的同步常常会造成程序性能的下降。因此,如果程序是单线程,则一定不要使用同步。
    (2)
同步方法而不要同步整个代码段
   对某个方法或函数进行同步比对 ......

Java调用SQL Server的存储过程详解

1使用不带参数的存储过程
  使用 JDBC 驱动程序调用不带参数的存储过程时,必须使用 call SQL 转义序列。不带参数的 call 转义序列的语法如下所示:
  
以下是引用片段:
{call procedure-name}
  作为实例,在 SQL Server 2005 AdventureWorks 示例数据库中创建以下存储过程:
  
以下是引用片段: ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号