String Encryption in RubyMotion

I'm trying to encrypt strings in RubyMotion - ideally AES, but weaker / older cyphers like Blowfish should only do well.

So far I have not managed to build a couple of modules: RNCrypto and CommonCrypto.

Suggestions? Has anyone else tried these pods?

Thanks, Adrian

+3


source to share


2 answers


Here's a necessary process if you currently want to use the CommonCrypto program:

  • make sure to include the module in your Rakefile or do the equivalent Bundler ritual
  • don't forget to include app.frameworks <<"Security" in Rakefile as well
  • then go to vendor / Pods / CommonCrypto and delete the sample .m file

Congratulations, you're all set!

Here's a quick (and dirty) sample:



iv = 'init_vector_here'
key = 'key_here'
plainText = 'This is plain text'

plainData = plainText.dataUsingEncoding(NSUTF8StringEncoding)
ivData = iv.dataUsingEncoding(NSUTF8StringEncoding)
keyData = key.dataUsingEncoding(NSUTF8StringEncoding)

status = NIL
result = plainData.dataEncryptedUsingAlgorithm(0, key: keyData, initializationVector: ivData, options: 0, error: status) # 0 = AES128
p result.base64EncodedString

      

For Base64 encoding, you need to enable NSData + Base64 module.

Thanks @ AwDogsGo2Heaven and @Jamon Holmgren for your helpful suggestions!

+1


source


If you are having trouble compiling CocoaPods, make sure you run rake clean

. As far as I know, CocoaPods should work fine with RubyMotion.

EDIT: Since the OP didn't post his solution as an answer, I'll post it here:



RNCryptor does not build for iOS6, and there is an option for ARC compatibility, but not yet integrated into the module.

As far as CommonCrypto is concerned, it has an example.m file that demonstrates its capabilities. This .m example has a main function that collides with the one created by RubyMotion. By removing it I was able to compile it successfully.

+3


source







All Articles