// [CRUCIBLE-SEED]
// category: insecure_crypto
// severity: critical
// language: java
// expected: DES cipher used for data encryption (56-bit key, broken algorithm)

import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class DataEncryptor {
    // Vulnerable: DES uses only 56-bit key, broken since 1999
    private static final String ALGORITHM = "DES";
    private static final byte[] KEY_BYTES = "8byteKey".getBytes();

    public static String encrypt(String plaintext) throws Exception {
        SecretKeySpec key = new SecretKeySpec(KEY_BYTES, ALGORITHM);
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return Base64.getEncoder().encodeToString(cipher.doFinal(plaintext.getBytes()));
    }

    public static String decrypt(String ciphertext) throws Exception {
        SecretKeySpec key = new SecretKeySpec(KEY_BYTES, ALGORITHM);
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.DECRYPT_MODE, key);
        return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)));
    }
}
