· 7 years ago · Oct 09, 2018, 03:02 AM
1public static void main(String[] args) {
2
3 String plainText = "Very secret data";
4 AES aesClient = new AES("client");
5 SecretKey AESKey = aesClient.getEncodedSecret();
6 RSA rsaClient = new RSA();
7 byte[] RSAcipher = rsaClient.EncryptSecretKey(AESKey);
8 String cipherData = aesClient.encryptAndSerialize(plainText);
9
10 // Assume that client sends the cipherData and RSAcipher to the server...
11 RSA serverRSA = new RSA();
12 SecretKey AESkeyServer = rsaServer.decryptAESKey(RSAcipher);
13
14 if (AESKey.equals(AESkeyServer)) System.out.println("equals");
15
16 AES aesServer = new AES();
17 String originalPlainText = aesServer.deserializeAndDecrypt(cipherData, AESkeyServer);
18 System.out.println(originalPlainText);
19
20 //voilaaa!
21}