I'm working on an iOS and Ruby on Rails application and need to transmit data encrypted from the iOS app to the Ruby on Rails application. My challenge is how to encode the data in Objective-C in a way that I can decode on the Rails side. I'm using the example in this SO question as the method to encrypt the data, and the example code shows what the encrypted data would look like this:
printf("%s\n", [[plain description] UTF8String]);
which creates output that looks like:
<3fe47b63 bd9a84ab 30dfb1a4 e409b60f>
My challenge is that I need to find a way to get this across the wire to the Rails application in a way that I can decode for use with OpenSSL code like:
def decrypt(data)
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
cipher.decrypt
cipher.key = cipher_key
cipher.iv = cipher_iv
decrypted_data = cipher.update(data)
decrypted_data << cipher.final
end
I'm thinking that Base64 encoding may be the best way to go as this data will end up in an HTTP header in JSON requests. It seems like I could use Base64.decode64 to decode the data on the Ruby side and pass it as the data to decrypt, but I'm hoping someone can guide me on whether this really is the best way to do it and, regardless of the encoding, how to turn a pointer to an NSData object like this:
NSData *cipher = [plain AES256EncryptWithKey:key];
into that encoded value to get it to the Rails app. Thanks!