Java 理解加密和解密程序时遇到的问题

Java 理解加密和解密程序时遇到的问题,java,encryption,Java,Encryption,我理解这个程序有问题。我主要怀疑的是那把秘密钥匙。为什么我们在程序中提到它,因为它是不安全的,就像任何打开程序的人都可以加密和解密一样,那么它是如何安全的呢 这是节目- package test; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputSt

我理解这个程序有问题。我主要怀疑的是那把秘密钥匙。为什么我们在程序中提到它,因为它是不安全的,就像任何打开程序的人都可以加密和解密一样,那么它是如何安全的呢

这是节目-

 package test;

 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import javax.crypto.Cipher;
 import javax.crypto.CipherInputStream;
 import javax.crypto.CipherOutputStream;
 import javax.crypto.SecretKey;
 import javax.crypto.SecretKeyFactory;
 import javax.crypto.spec.DESKeySpec;
 public class CipherExample {
    public static void main(String[] args) {
        try {
            //the string key is open here so anyone can change the key and encrypt and decrypt so i didnt understand the use of this program
            String key = "12345678";
            FileInputStream fis = new FileInputStream("original.txt");
            FileOutputStream fos = new FileOutputStream("encrypted.txt");
            encrypt(key, fis, fos);
            FileInputStream fis2 = new FileInputStream("encrypted.txt");
            FileOutputStream fos2 = new FileOutputStream("decrypted.txt");
            decrypt(key, fis2, fos2);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public static void encrypt(String key, InputStream is, OutputStream os) throws Throwable {
        encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);
    }
    public static void decrypt(String key, InputStream is, OutputStream os) throws Throwable {
        encryptOrDecrypt(key, Cipher.DECRYPT_MODE, is, os);
    }

在我看来,这是一个简单的演示程序。在“安全”程序中,您将让用户输入密钥,而不是硬编码。但这只是为了显示我怀疑的算法。@Floris好的,谢谢你的回复。你能帮我使用其他程序密钥生成器来保护它吗?因为我想我需要编写两个程序,一个用于加密,另一个用于解密,但我没有那么多想法。如果你不真正理解你在做什么,我强烈建议你这样做现在还不能解决真正的密码问题。通常你会加密一些在某种程度上有价值的东西——你需要做得正确。我的建议是:找一个专业的工具来做这项工作,不要自己做。