· 7 years ago · Jan 19, 2019, 03:14 PM
1public class NewMain2 {
2
3 public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, IllegalBlockSizeException, ClassNotFoundException {
4 SecretKey key = KeyGenerator.getInstance("DES").generateKey(); // Crea una chiave
5 Cipher encrypt_cipher = Cipher.getInstance("DES"); // Crea un cipher
6 encrypt_cipher.init(Cipher.ENCRYPT_MODE, key); // Inizializza il cipher alla modalita encrypt
7 A prova = new A (5, "prova"); // nuovo oggetto di classe A
8 SealedObject prova_sealed = new SealedObject(prova, encrypt_cipher); // critta l'oggetto usando il cipher
9 A prova_decrittata = (A) prova_sealed.getObject(key); // decritta l'oggetto usando la chiave
10 }
11
12}