Вопрос

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

Это было полезно?

Решение 2

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!

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top