fwrite 、 fputs 字节安全
我想通过 POST 将数据发送到 php 页面,我需要完全按原样存储字节,但我无法做到这一点。当我发送 138 字节时,fputs 和 fwrite 返回 133。VB.NET
$fh = fopen($myFile, 'ab') or die("can't open file");
echo fputs($fh, $_POST['data'] ,strlen($_POST['data']));
fclosw
:
Dim ar As System.Text.UTF8Encoding = New System.Text.UTF8Encoding
Request.ContentLength = ar.GetByteCount(PostData)
ContentType = "application/x-www-form-urlencoded"
SW = New StreamWriter(Request.GetRequestStream(), ar)
SW.Write(PostData)
-edit 这是加密数据函数
Public Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
Rijndael.Key = SHA256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key))
Rijndael.Mode = CipherMode.ECB
Dim Buffer As Byte() = ASCIIEncoding.UTF8.GetBytes(stringToEncrypt)
Return Convert.ToBase64String(Rijndael.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function
编辑 例如,原始加密字符串:
j/aokbSUDP1nAD7KafnDoLSmI93sOLiroTwcQIUS/Xw8eUlUZA58OULXCtsnkKqOe+UXlFP6vKuTIWxVMRBZLiBiIOZomNsvoIfM4dv2UzAk2q5mpjo4/0E9lPvu4I7X
发送后
j/aokbSUDP1nAD7KafnDoLSmI93sOLiroTwcQIUS/Xw8eUlUZA58OULXCtsnkKqOe UXlFP6vKuTIWxVMRBZLiBiIOZomNsvoIfM4dv2UzAk2q5mpjo4/0E9lPvu4I7X
I want to send data via POST to a php page, I need to store the bytes exactly as they are but I wasn't able to do it. When I send 138 bytes, fputs and fwrite returns 133.
$fh = fopen($myFile, 'ab') or die("can't open file");
echo fputs($fh, $_POST['data'] ,strlen($_POST['data']));
fclosw
VB.NET:
Dim ar As System.Text.UTF8Encoding = New System.Text.UTF8Encoding
Request.ContentLength = ar.GetByteCount(PostData)
ContentType = "application/x-www-form-urlencoded"
SW = New StreamWriter(Request.GetRequestStream(), ar)
SW.Write(PostData)
-edit
this is the encrypted data function
Public Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
Rijndael.Key = SHA256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key))
Rijndael.Mode = CipherMode.ECB
Dim Buffer As Byte() = ASCIIEncoding.UTF8.GetBytes(stringToEncrypt)
Return Convert.ToBase64String(Rijndael.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function
EDITED
example, original encrypted string:
j/aokbSUDP1nAD7KafnDoLSmI93sOLiroTwcQIUS/Xw8eUlUZA58OULXCtsnkKqOe+UXlFP6vKuTIWxVMRBZLiBiIOZomNsvoIfM4dv2UzAk2q5mpjo4/0E9lPvu4I7X
after sending
j/aokbSUDP1nAD7KafnDoLSmI93sOLiroTwcQIUS/Xw8eUlUZA58OULXCtsnkKqOe UXlFP6vKuTIWxVMRBZLiBiIOZomNsvoIfM4dv2UzAk2q5mpjo4/0E9lPvu4I7X
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看不出这行不通的原因:
I don't see a reason why this wouldn't work: