hohl / MIHCrypto

OpenSSL wrapper for Objective-C [cryptography]
MIT License
341 stars 68 forks source link

Supporting ECB mode for AES Encryption #46

Open indiandragon opened 7 years ago

indiandragon commented 7 years ago

Hi @hohl ,

I know CBC mode for AES encryption is much secure than ECB mode, but as the server I'm connecting to has ECB mode of encryption/decryption I'm forced to use the same on the iOS client. Can you give me some pointers on implementing ECB mode in the MIHCrypto ?

hohl commented 7 years ago

Hey, @indiandragon

It shouldn't be too hard to extend MIHAESKey to support ECB. Right now it is hardcoded to use the CBC chiper in lines 126 to 136 and lines 176 to 184. You could try to replace this hardcoded lines by adding for ex. a chiper property to the MIHAESKey class and then add a switch construct in those lines.

The EVP_aes_256_cbc() function used in the above linked lines constructs the chiper (256 bit CBC chiper for AES) which is then used in the lines below for the encryption process. There must be some similar chiper function for ECB too in the OpenSSL documentation.

indiandragon commented 7 years ago

Hey @hohl , thanks for the information. I'll update when I implement the same.