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.

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

报告相同问题?

悬赏问题

  • ¥15 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网