fwrite 、 fputs 字节安全

发布于 2024-11-04 10:40:26 字数 1304 浏览 1 评论 0原文

我想通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2024-11-11 10:40:26

我看不出这行不通的原因:

$connection = fopen($file, 'ab');
fwrite($connection, urldecode($_POST['data']));
fclose($connection);

I don't see a reason why this wouldn't work:

$connection = fopen($file, 'ab');
fwrite($connection, urldecode($_POST['data']));
fclose($connection);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文