import java.io.*;import javax.crypto.*;import javax.crypto.spec.*; public class Encryptor{ public static void main(String [] args) { FileOutputStream fos = null; String secret = "Шифруемый текст."; try { String keyfile = "file.txt"; String algorithm = "DESede"; KeyGenerator kg = KeyGenerator.getInstance(algorithm); SecretKey key = kg.generateKey(); Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); ObjectOutputStream oos = new ObjectOutputStream(new CipherOutputStream(new FileOutputStream("files.txt"), cipher)); oos.writeObject(secret); fos = new FileOutputStream(keyfile); SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm); DESedeKeySpec keyspec = (DESedeKeySpec) skf.getKeySpec(key, DESedeKeySpec.class); fos.write(keyspec.getKey()); fos.close(); oos.close(); } catch (Exception e) { e.printStackTrace(); } }}