3

I'm trying to encrypt strings in RubyMotion - ideally AES but weaker/older cyphers such as Blowfish should do just fine.

So far I have failed at compiling a couple of pods: RNCrypto and CommonCrypto.

Suggestions? Anyone else tried these pods?

Thank you, Adrian

Adrian Spinei
  • 550
  • 5
  • 15
  • This is available through Apple's frameworks, please see this question: http://stackoverflow.com/questions/1400246/aes-encryption-for-an-nsstring-on-the-iphone (which Rubymotion has access to all of them as far as I know, this is pretty simple just try it in the terminal after launching an app) – AwDogsGo2Heaven Jan 28 '13 at 22:30
  • Seems like a good suggestion, I will try it. – Adrian Spinei Jan 29 '13 at 19:39
  • It would be better than using a pod for simple string encryption, don't want to bloat your program with pods you don't need. – AwDogsGo2Heaven Jan 29 '13 at 19:45
  • Unfortunately the code doesn't port nicely to RubyMotion, I get an undefined method `AES256EncryptWithKey' for # – Adrian Spinei Jan 29 '13 at 21:49
  • 1
    for your CommonCrypto pod, are you including Security framework in your rake file? ex: app.frameworks << 'Security' – AwDogsGo2Heaven Jan 30 '13 at 16:21

2 Answers2

3

If you're having trouble compiling CocoaPods, make sure you run a rake clean. CocoaPods should work fine with RubyMotion as far as I know.

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

RNCryptor doesn't build for iOS6, and there's a pull for ARC compatibility but not yet integrated in the pod.

As for CommonCrypto, it has an example.m file showcasing its capabilities. This example.m includes a main function which clashes with the one created by RubyMotion. By deleting it, I've managed to make it compile successfully.

Community
  • 1
  • 1
Jamon Holmgren
  • 23,738
  • 6
  • 59
  • 75
  • Tried that, no luck. Have you succeeded at compiling one of the pods mentioned here? I'm using rvm with Ruby 1.9.2-p320 and all latest version for cocoapods. – Adrian Spinei Jan 29 '13 at 19:39
  • I did a `rake` with those pods added and didn't have an issue. I didn't have them implemented anywhere, though. – Jamon Holmgren Jan 29 '13 at 21:30
  • try deleting the vendor folder, and raking again. – AwDogsGo2Heaven Jan 30 '13 at 16:18
  • 1
    Nope. Here's what I found: RNCryptor doesn't build for iOS6, and there's a pull for ARC compatibility but not yet integrated in the pod. As for CommonCrypto, it has an example.m file showcasing its capabilities. This example.m includes a main function which clashes with the one created by RubyMotion. By deleting it, I've managed to make it compile successfully. – Adrian Spinei Jan 30 '13 at 21:33
  • Sounds like you need to add this as the answer to your question. – Jamon Holmgren Jan 31 '13 at 00:25
  • Yep, add it and mark it as an answer so future readers can easily find it. – AwDogsGo2Heaven Jan 31 '13 at 18:00
  • I was out at a conference and just got back. I'm adding the answer together with a basic code sample. – Adrian Spinei Feb 13 '13 at 20:55
1

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

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

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 have to include the 'NSData+Base64' pod.

Thank you @AwDogsGo2Heaven and @Jamon Holmgren for your helpful suggestions!

Adrian Spinei
  • 550
  • 5
  • 15