ZipFile 
ZipInputStream 
ZipOutputStream 

解决方案 »

  1.   

    import java.util.Random;public class SimpleEncoder {

    private static Random random = new Random();

    public static void main(String[] args){
    String s = "只要不是加密前的字符就可以了,能够还原。加密和还原的速度要很快。关键是要快";
    System.out.println(s+'\n');
    byte[] key = getRandomKey(5);
    byte[] s1 = encrypt(key,s.getBytes());
    System.out.println(new String(s1)+'\n');
    byte[] s2 = decrypt(key,s1);
    System.out.println(new String(s2)+'\n');
    }

    public static byte[] getRandomKey(int length) {
    if(length <= 0){
    throw new IllegalArgumentException();
    }
    int rand, index=0;
    byte[] result = new byte[length];
    for(int i=0; i<(length/5); i++){
    rand = random.nextInt();
    for(int j=0; j<5; j++) {
    result[index++] = (byte)(rand&63);
    rand >>= 6;
    }
    }
    rand = random.nextInt();
    for(int i=0; i<(length%5); i++) {
    result[index++] = (byte)(rand&63);
    rand >>= 6;
    }
    return result;
    }

    public static byte[] encrypt(byte[] key, byte[] b) {
    if(key==null || b==null){
    throw new IllegalArgumentException();
    }
    int index = 0;
    byte[] result = (byte[])b.clone();
    for(int i=0; i<(b.length/key.length); i++){
    for(int j=0; j<key.length; j++){
    result[index++] += key[j];
    }
    }
    for(int i=0; i<(b.length%key.length); i++){
    result[index++] += key[i]; 
    }
    return result;
    }

    public static byte[] decrypt(byte[] key, byte[] b) {
    if(key==null || b==null){
    throw new IllegalArgumentException();
    }
    int index = 0;
    byte[] result = (byte[])b.clone();
    for(int i=0; i<(b.length/key.length); i++){
    for(int j=0; j<key.length; j++){
    result[index++] -= key[j];
    }
    }
    for(int i=0; i<(b.length%key.length); i++){
    result[index++] -= key[i]; 
    }
    return result;
    }
    }
      

  2.   

    如果要不可逆,用md5
    否则,你可以去看看jive上的有个加密、解密的算法。