Dimi Ortega
Dimi Ortega

Reputation: 1

RSA Encryption-Decryption of AES key and storing in file

just a question if my way to do it is okay. I made a filecrypter in java there i use a random generated AES key and encrypt files with it. The AES key will be encrypted using RSA and will also be stored in the outpufile together with the random IV. On decryption i read the first n bytes (256byte in my case) and decrypt it with my private RSA key and then i decrypt with the AES key the rest of the file.

My main question is it okay to include the encrypted AES key in the encrypted file? It seem comfortable to me because every file i encrypt has its own random key included that was encrypted with RSA key. Is this bad practice?

Upvotes: 0

Views: 971

Answers (1)

Nirav Chhatrola
Nirav Chhatrola

Reputation: 512

Execution of AES is more faster than RSA (for same key sizes).
So you can create a structure like bellow....

------------------------------------------------
|     |                                        |
| IV  |  Your encrypted data                   |
|     |                                        |
------------------------------------------------

you can store your IV with your encrypted data.
Lets say your IV is 20 size of byte[] than store it with encrypted data.
And when you want to decrypt data than first get initial 20 bytes from array than rest of data is your encrypted data.
And you know the size of IV .. so you can easily depart IV and encrypted data from whole data (IV + EncryptedData).

Above is not the exact solution of your problem.
But you can surly use above one....

Upvotes: 1

Related Questions