gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:51:58 26 4
gpt4 key购买 nike

我知道有 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com