3

我正在尝试在 RubyMotion 中加密字符串-理想情况下是 AES,但较弱/较旧的密码(例如 Blowfish)应该可以。

到目前为止,我未能编译几个 pod:RNCrypto 和 CommonCrypto。

建议?其他人尝试过这些豆荚吗?

谢谢你,阿德里安

4

2 回答 2

3

如果您在编译 CocoaPods 时遇到问题,请确保您运行rake clean. 据我所知,CocoaPods 应该可以与 RubyMotion 一起正常工作。

编辑:由于 OP 没有发布他的解决方案作为答案,我会在这里发布:

RNCryptor 不是为 iOS6 构建的,并且有 ARC 兼容性的吸引力,但尚未集成到 pod 中。

至于 CommonCrypto,它有一个 example.m 文件展示其功能。这个 example.m 包含一个与 RubyMotion 创建的主函数发生冲突的主函数。通过删除它,我设法使其编译成功。

于 2013-01-29T01:42:52.363 回答
1

如果您当前想要使用 CommonCrypto pod,以下是必要的过程:

  • 确保将 pod 包含在 Rakefile 中或执行等效的 Bundler 仪式
  • 不要忘记在 Rakefile 中包含app.frameworks << 'Security'
  • 然后转到 vendor/Pods/CommonCrypto 并删除文件 example.m

恭喜你,一切准备就绪!

这是一个快速(又脏)的示例:

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

对于 Base64 编码,您必须包含“NSData+Base64”吊舱。

感谢@AwDogsGo2Heaven 和@Jamon Holmgren 的有用建议!

于 2013-02-13T21:12:43.047 回答