• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: Java
  • 标签: JavaDES  Demo  

资源简介

JavaDES通过秘钥加密解密Demo

资源截图

代码片段和文件信息

package com.cxq.tools;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.Random;

public class DataServiceDecrypt extends Properties {

private static final long serialVersionUID = 1L;

private ListEnumerationAdapterject> keyList = new ListEnumerationAdapterject>();
public DataServiceDecrypt() {
}
/**
 * 从指定路径加载信息到Properties
 * 
 * @param path
 */
public DataServiceDecrypt(String path) {
try {
InputStream is = new FileInputStream(path);
this.load(is);
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(“指定文件不存在!“);
} catch (IOException e) {
e.printStackTrace();
}
}

/**
 * 重写put方法,按照property的存入顺序保存key到keyList,遇到重复的后者将覆盖前者。
 */
@Override
public synchronized object put(object key object value) {
if (keyList.contains(key)) {
keyList.remove(key);
}
keyList.add(key);
return super.put(key value);
}
/**
 * 获取Properties中key的有序集合
 * @return
 */
public Listject> getKeyList() {
      return keyList;
   }

/**
 * 保存Properties到指定文件,并指定对应存放编码
 * @param path
 *            指定路径
 * @param charset
 *            文件编码
 */
public void store(String path) {
      if (path != null && !““.equals(path)) {
         try {
            OutputStream os = new FileOutputStream(path);
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            this.store(bw null);
            bw.close();
         } catch (FileNotFoundException e) {
            e.printStackTrace();
         } catch (IOException e) {
            e.printStackTrace();
         }
      } else {
         throw new RuntimeException(“存储路径不能为空!“);
      }
   }
/**
 * 重写keys方法
 */
@Override
   public synchronized Enumerationject> keys() {
      keyList.reset();
      return keyList;
   }
/**
 * ArrayList到Enumeration的适配器
 */
private static class ListEnumerationAdapter extends ArrayList
implements
Enumeration {
private static final long serialVersionUID = 1L;
private int index = 0;
public boolean hasMoreElements() {
         return index < this.size();
      }
public T nextElement() {
if (this.hasMoreElements()) {
return this.get(index++);
}
return null;
}

/**
 * 重置index的值为0,使得Enumeration可以继续从头开始遍历
 */
public void reset() {
this.index = 0;
}
}
private static char movePosition(char cSrc int nLen) {
int nSrc = 0;
if (cSrc >= ‘ ‘ && cSrc <= ‘:‘)
nSrc = cSrc - 32;
if

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5516  2017-04-19 11:33  DataServiceDecryptjiemi.java

     文件       6286  2017-04-19 11:36  DataServiceEncryptjiami.java

----------- ---------  ---------- -----  ----

                11802                    2


评论

共有 条评论