我从网上看了一个加密解密的程序感觉不错想应用,但是我的字符串都是存在文件中的(System.ini)共四行,要求一行一行存,一行行读。但是那个加密解密的程序中加密后生成的是字节码数组,按我的做法怎么都是出错请各位帮帮忙教一下我到底如何才能把加密后的文件正确存入文件,并正确从文件中取出?请给出详细源代码
加密解密源代码:
package bestteam;
import java.security.*;
import javax.crypto.*;
import java.io.*;
public class Crypt{
private static String Algorithm = "DES ";
static boolean debug = false;
static
{
Security.addProvider(new com.sun.crypto.provider.SunJCE());
}
public static byte[] getKey()
throws Exception
{
KeyGenerator keygen =KeyGenerator.getInstance(Algorithm);
SecretKey deskey = keygen.generateKey();
return deskey.getEncoded();
}
public static byte[] encode(byte[] input, byte[] key)
throws Exception
{
SecretKey deskey = new javax.crypto.spec.SecretKeySpec(key,Algorithm);
Cipher c1 = Cipher.getInstance(Algorithm);
c1.init(Cipher.ENCRYPT_MODE, deskey);
byte[] cipherByte = c1.doFinal(input);
return cipherByte;
}