Class RSAAESHybrid
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decrypt0(PrivateKey privateKey, byte[] encryptedAESKey, byte[] encryptedData) encrypt(byte[] inputData) The key of the pair represents the compressed and Base64 encoded final value.static Pair<byte[],byte[]> encrypt0(byte[] content) static voidstatic KeyPairstatic StringgetMainMethod(String cipherAlgorithm) static byte[]merge(byte[] aes, byte[] content) static Pair<byte[],byte[]> splitString(String whole)
-
Field Details
-
AES_CIPHER_ALGORITHM
- See Also:
-
RSA_CIPHER_ALGORITHM
- See Also:
-
-
Constructor Details
-
RSAAESHybrid
public RSAAESHybrid()
-
-
Method Details
-
getMainMethod
-
encrypt
The key of the pair represents the compressed and Base64 encoded final value. -
merge
public static byte[] merge(byte[] aes, byte[] content) -
splitString
-
encrypt0
- Throws:
Exception
-
decrypt0
public static byte[] decrypt0(PrivateKey privateKey, byte[] encryptedAESKey, byte[] encryptedData) throws Exception - Throws:
Exception
-
generateKeyPair
-
generateAndPrintKeyPair
public static void generateAndPrintKeyPair()
-