import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.engines.DESEngine;
import org.bouncycastle.crypto.modes.CFBBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import javax.crypto.*;
import java.security.*;
import java.util.Base64;
public class DESExample {
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {
// Генерируем случайный ключ DES
KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
SecretKey secretKey = keyGenerator.generateKey();
// Создаем шифр DES с режимом CFB и инициализируем его сгенерированным ключом
Cipher desCipher = Cipher.getInstance("DES/CFB/NoPadding");
desCipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Шифруем текст
String plaintext = "Hello, DES!";
byte[] ciphertext = desCipher.doFinal(plaintext.getBytes());
// Дешифруем текст
desCipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedText = desCipher.doFinal(ciphertext);
System.out.println("Original Text: " + plaintext);
System.out.println("Encrypted Text: " + Base64.getEncoder().encodeToString(ciphertext));
System.out.println("Decrypted Text: " + new String(decryptedText));
}
}