I am new to Iphone development , I want to create an application in which I have to upload some data on php server using my Iphone application. For this I have an file on the Iphone whose content I have to upload on php server. For this I have converted the content of the file in NSData and now I want to encrypt this nsdata object and then pass it to the php server and on php server firstly I have to decrypt the nsdata object then I have to upload it on the server.
我是Iphone开发的新手,我想要创建一个应用程序,我必须使用我的Iphone应用程序在php服务器上上传一些数据。为此,我在Iphone上有一个文件,我必须在php服务器上上传其内容。为此,我在NSData中转换了文件的内容现在我要加密这个NSData对象然后把它传递给php服务器在php服务器上,首先我要解密NSData对象然后我要把它上传到服务器上。
But I am not able to find any way by which I can encrypt some data in Iphone app and then decrypt it in php.
但是我找不到任何方法可以在Iphone应用程序中加密一些数据,然后在php中解密。
And also I want to compress the encrypted data before transferring it to php and then uncompress that data on php.
我还想在将加密数据传输到php之前对其进行压缩,然后在php上解压该数据。
The complete flow of my application is
我的应用程序的整个流程是
IPhone
NSData --> Encrypted NsData --> Compressed Encrypted Data
NSData——>加密的NSData——>压缩加密数据
php
Compressed Encrypted Data --> uncompressed encrypted data --> decrypted (original) NSData.
压缩加密数据——>未压缩加密数据——>解密(原始)NSData。
Can some one help me how can I develop such application?
有人能帮助我如何开发这样的应用吗?
Thanks in advance.
提前谢谢。
Gaurav
Gaurav
3 个解决方案
#1
3
I wrote an article about this in my blog: http://www.em-motion.mobi/?p=139
我在我的博客http://www.em-motion.mobi/?
#2
0
The best way would probably be to encrypt NSData with a public key crypto system, distribute a public key with the application, encrypt, then only your PHP application would be able to decrypt with the private key.
最好的方法可能是使用公钥加密系统加密NSData,向应用程序分发公钥,加密,然后只有PHP应用程序才能使用私钥解密。
In PHP, you can use OpenSSL to implement public/private key encryption.
在PHP中,可以使用OpenSSL实现公钥/私钥加密。
$key = openssl_pkey_get_private('file:///path/to/my/secure/privatekey', $my_secure_passphrase);
openssl_private_decrypt($nsdata, $decrypted_data, $key);
openssl_private_decrypt() is incredibly useful in that only it can decrypt the NSData from your phones as long as only you possess the private key. I'm not sure what the iPhone has in the way of encryption, but I'm positive there's a way to encrypt using a public key.
openssl_private_decrypt()非常有用,因为只有它才能解密手机上的NSData,只要您拥有私钥即可。我不太清楚iPhone的加密方式,但我确信有一种使用公钥加密的方法。
#3
0
You might want to give a look to AES encryption support in CommonCrypto .
您可能需要查看CommonCrypto中的AES加密支持。
I'd suggest writing a category for NSData that handles the encryption. Given that you need to be able to interoperate between different systems, be sure to understand the concepts of "salt" and "initial value vector (IV)".
我建议为NSData编写一个类别来处理加密。考虑到您需要能够在不同的系统之间进行互操作,请务必理解“salt”和“初始值向量(IV)”的概念。
As Xorlev said, the best security is obtained by using a public key crypto.
正如Xorlev所说,最好的安全性是通过使用公钥加密获得的。
Take care about how openssl stores the salt, it's before the encrypted data. something like:
注意openssl是如何存储盐的,它在加密数据之前。喜欢的东西:
the string "Salted__" followed by the 8 bytes salt and the encrypted data.
字符串“Salted__”后面跟着8字节的salt和加密数据。
If you don't need strong security, just do symmetric crypto.
如果不需要强安全性,只需执行对称加密。
#1
3
I wrote an article about this in my blog: http://www.em-motion.mobi/?p=139
我在我的博客http://www.em-motion.mobi/?
#2
0
The best way would probably be to encrypt NSData with a public key crypto system, distribute a public key with the application, encrypt, then only your PHP application would be able to decrypt with the private key.
最好的方法可能是使用公钥加密系统加密NSData,向应用程序分发公钥,加密,然后只有PHP应用程序才能使用私钥解密。
In PHP, you can use OpenSSL to implement public/private key encryption.
在PHP中,可以使用OpenSSL实现公钥/私钥加密。
$key = openssl_pkey_get_private('file:///path/to/my/secure/privatekey', $my_secure_passphrase);
openssl_private_decrypt($nsdata, $decrypted_data, $key);
openssl_private_decrypt() is incredibly useful in that only it can decrypt the NSData from your phones as long as only you possess the private key. I'm not sure what the iPhone has in the way of encryption, but I'm positive there's a way to encrypt using a public key.
openssl_private_decrypt()非常有用,因为只有它才能解密手机上的NSData,只要您拥有私钥即可。我不太清楚iPhone的加密方式,但我确信有一种使用公钥加密的方法。
#3
0
You might want to give a look to AES encryption support in CommonCrypto .
您可能需要查看CommonCrypto中的AES加密支持。
I'd suggest writing a category for NSData that handles the encryption. Given that you need to be able to interoperate between different systems, be sure to understand the concepts of "salt" and "initial value vector (IV)".
我建议为NSData编写一个类别来处理加密。考虑到您需要能够在不同的系统之间进行互操作,请务必理解“salt”和“初始值向量(IV)”的概念。
As Xorlev said, the best security is obtained by using a public key crypto.
正如Xorlev所说,最好的安全性是通过使用公钥加密获得的。
Take care about how openssl stores the salt, it's before the encrypted data. something like:
注意openssl是如何存储盐的,它在加密数据之前。喜欢的东西:
the string "Salted__" followed by the 8 bytes salt and the encrypted data.
字符串“Salted__”后面跟着8字节的salt和加密数据。
If you don't need strong security, just do symmetric crypto.
如果不需要强安全性,只需执行对称加密。