Cómo implementar el cifrado AES de Java de 256 bits con CBC

He leído los siguientes hilos y me han ayudado un poco, pero estoy buscando un poco más de información.

Cómo escribir el cifrado y descifrado AES / CBC / PKCS5Padding con el parámetro de vector de inicialización para BlackBerry

Encriptación Java AES de 256 bits

Básicamente, lo que estoy haciendo es escribir un programa que cifrará una solicitud para que se envíe a través de TCP / IP y luego se descifre mediante un programa servidor. El cifrado tendrá que ser AES y, al investigar un poco, necesito usar CBC y PKCS5Padding. Así que básicamente necesito una clave secreta y una IV también.

La aplicación que estoy desarrollando es para un teléfono, así que quiero usar los paquetes de seguridad de java para mantener el tamaño bajo. He hecho el diseño, pero no estoy seguro de la implementación del IV y la clave compartida.

Aquí hay un código:

// My user name
byte[] loginId = "login".getBytes();

byte[] preSharedKey128 = "ACME-1234AC".getBytes();
byte[] preSharedKey192 = "ACME-1234ACME-1234A".getBytes();
// 256 bit key
byte[] preSharedKey256 = "ACME-1234ACME-1234ACME-1234".getBytes();
byte[] preSharedKey = preSharedKey256;

// Initialization Vector
// Required for CBC
byte[] iv ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
IvParameterSpec ips = new IvParameterSpec(iv);


byte[] encodedKey = new byte[loginId.length + preSharedKey.length];

System.arraycopy(loginId, 0, encodedKey, 0, loginId.length);
System.arraycopy(preSharedKey, 0, encodedKey, loginId.length, preSharedKey.length);

// The SecretKeySpec provides a mechanism for application-specific generation
// of cryptography keys for consumption by the Java Crypto classes.

// Create a key specification first, based on our key input.
SecretKey aesKey = new SecretKeySpec(encodedKey, "AES");

// Create a Cipher for encrypting the data using the key we created.
Cipher encryptCipher;

encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// Initialize the Cipher with key and parameters
encryptCipher.init(Cipher.ENCRYPT_MODE, aesKey, ips);

// Our cleartext
String clearString = "33,8244000,9999,411,5012022517,0.00,0,1,V330";
byte[] cleartext = clearString.getBytes();

// Encrypt the cleartext
byte[] ciphertext = encryptCipher.doFinal(cleartext);

// Now decrypt back again...
// Decryption cipher
Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// Initialize PBE Cipher with key and parameters
decryptCipher.init(Cipher.DECRYPT_MODE, aesKey, ips);

// Decrypt the cleartext
byte[] deciphertext = decryptCipher.doFinal(ciphertext);

En pocas palabras, lo que debería hacer es cifrar algún mensaje que el servidor pueda descifrar sin que el servidor necesite obtener una clave o IV del teléfono. ¿Hay alguna manera de hacer esto donde pueda asegurar la IV y la clave en el teléfono y aún así tener la clave y la IV conocidas por el servidor? Siéntase libre de decirme que aclare las cosas si no lo son.

Respuestas a la pregunta(2)

Su respuesta a la pregunta