douweng7308 2015-05-20 09:36
浏览 46
已采纳

在iOS中加密NSString(不是NSData) - >发送到PHP服务器 - >让PHP服务器解密吗?

I know there is openSSL but I just want to use encryption.

Here is exactly what I wish to do.

1) encrypt NSString in xcode(objective-c) with AES-128 or whatever encryption method that works

2) send the encrypted NSString to PHP server using POST method. The parameter that will be sent to PHP server would look something like:

 @"fromClient1=string1&fromClient2=string2"

3) PHP server receives that data with something like this:

 $receivedStr1 = $_POST['fromClient1']; // string1
 $receivedStr2 = $_POST['fromClient2']; // string2

4) let PHP server decode $receivedStr1 and $receivedStr2 into plain texts

I have looked at https://github.com/RNCryptor/RNCryptor, but it's all about NSData encryption.

How do you receive encrypted NSData in PHP?? I only know how to use

$fromClient = $_POST['someData'];

but it won't work if the whole parameter is encrypted...

Can anyone help me out?? The purpose of this is to send the user's password( = NSString) to PHP server securely.

  • 写回答

1条回答 默认 最新

  • dongyiluan1718 2015-05-20 10:57
    关注

    Following on from @Rory McKinnel, this code converts data into a base64 string which can be converted back into plain text or data (look here for more info).

    To convert data in Objective-C:

    NSString *base64String = [myData base64EncodedStringWithOptions:0];
    

    Or in Swift:

    let base64String = myData.base64EncodedStringWithOptions(options: 0)
    

    EDIT:

    NSString has two useful methods : 1) - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding and - (NSString *)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet *)allowedCharacters.

    These methods help convert an NSString into a legal URL string according to the docs these methods return:

    A new string made by replacing in the receiver all percent escapes with the matching characters as determined by the given encoding encoding. Returns nil if the transformation is not possible, for example, the percent escapes give a byte sequence not legal in encoding.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)