javascript - 如何在 Reactjs 中加密和解密对象数据
问题描述
我有一个具有三个属性的对象to name
。 message
我想加密我想发送name
并且message
只有一个属性值。如何从接收方name
返回message
// 我有这样的对象
const user={
to:1235,
name:"fox"
message:"Hi"
}
//我想这样发送
const user={
to:1235,
name:"fox&&message:"hii",
}
//我怎样才能得到名字和消息
解决方案
您可以通过使用字符串操作轻松解密。首先,您将获得name
Post 参数中包含的数据。假设我们在服务器端有这样的数据。
let encoded_data = "alice&message:hello world"
然后我们将这个字符串拆分为&
let split_data = encoded_data.split('&')
let name = split_data[0] //this contains value alice
现在将拆分 split_data[1] 其中包含message:hello world
let message = split_data[1].split(':')[1]
推荐阅读
- autodesk-forge - 正确定位聚合 svf 模型
- xml - xsl - 为以前缀开头的标签创建嵌套结构
- python - 不同的行为 Anaconda 提示符与命令提示符
- javascript - 是否可以在 Javascript 中创建一个“class extends A {} instanceof A”为真的类 A?
- android - 哪些Android设备/操作系统支持BLE外设模式
- ruby-on-rails - ruby中的间歇性未初始化常量错误
- javascript - 将反应虚拟化表从 javascript 转换为 typescript - 类型问题
- lua - 如何使用 pandoc 与 lua-filters 对齐文本?
- python - 在发送 Python smtplib 之前检查电子邮件的完整大小
- python - 如何在python列表中找到除0之外的任何数字的第一个索引?