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

标签 php ios objective-c encryption aes

我知道有 openSSL,但我只想使用加密。

这正是我想做的。

1) 使用 AES-128 或任何有效的加密方法在 xcode(objective-c) 中加密 NSString

2) 使用 POST 方法将加密的 NSString 发送到 PHP 服务器。将发送到 PHP 服务器的参数类似于:

 @"fromClient1=string1&fromClient2=string2"

3) PHP 服务器接收类似这样的数据:

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

4) 让 PHP 服务器将 $receivedStr1 和 $receivedStr2 解码成纯文本

我看过https://github.com/RNCryptor/RNCryptor ,但这全都与 NSData 加密有关。

如何在 PHP 中接收加密 NSData?我只知道怎么用

$fromClient = $_POST['someData'];

但是如果整个参数都加密了就不行了...

谁能帮帮我??这样做的目的是将用户的密码(= NSString)安全地发送到 PHP 服务器。

最佳答案

继@Rory McKinnel 之后,此代码将数据转换为 base64 字符串,该字符串可以转换回纯文本或数据 (look here for more info)。

在 Objective-C 中转换数据:

NSString *base64String = [myData base64EncodedStringWithOptions:0];

或者在 Swift 中:

let base64String = myData.base64EncodedStringWithOptions(options: 0)

编辑:

NSString 有两个有用的方法:1) - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding- (NSString *)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet * )allowedCharacters.

这些方法有助于将 NSString 转换为合法的 URL 字符串 根据文档,这些方法返回:

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.

关于php - 在 iOS 中加密 NSString(不是 NSData)-> 发送到 PHP 服务器-> 让 PHP 服务器解密?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30345872/

相关文章:

php - 即使我知道参数的类型,我还需要准备语句吗?

php - 我正在使用 fputcsv() 创建一个 .csv 文件,我想在 PHPMailer 中使用 AddAttachment() 来自动发送它

php - POST 调用无法正常工作

objective-c - 如何在 iOS 上使用 Facebook SDK 3.1 获取用户的电子邮件?

ios - 将 NSSecureCoding 转换为 NSData - Xcode - Swift

php - 通过php导入excel文件到mysql数据库

ios - 存档已提交 :Ld */Objects-normal/arm64/test normal arm64

ios - 从 CFData : Arithmetic on a pointer to incomplete type 读取像素字节

ios - 应用两次排序无法正常工作

iphone - 如何为 UITextView 设置圆角?