Class RSAAESHybrid

java.lang.Object
org.kingdoms.utils.security.RSAAESHybrid

public final class RSAAESHybrid extends Object
Data -> AES -> RSA -> GZIP -> Base64 => Base64 -> GZIP -> RSA -> AES -> Data

Encrypts the main message using an AES symmetric key (unlimited length content encryption) then encrypts the AES key itself with an asymmetric RSA-2048 encryption. This causes to have two separate data, in order to send it, the two are merged together with the fixed encrypted AES key (256 bytes) at the beginning and the rest of the encrypted content. Then the resultant byte array is compressed with GZIP and the resultant compressed byte array is encoded in Base64 for easier ASCII data exchange. The same processed is reversed for decryption.

RSA is a fixed-length encryption. RSA-2048 can only encrypt 256 bytes at a time. Using multiple fixed RSA encryption blocks will decrease the security. So instead AES is used to encrypt variable-length data and the AES private fixed-length key itself is encrypted with RSA.

The private AES key for each server is generated per session (server start) and the public RSA key is provided below as a byte array.