首页 > 编程语言 >简单的C#&PHP对称加解密

简单的C#&PHP对称加解密

时间:2023-01-05 17:31:44浏览次数:46  
标签:index C# 加解密 int Length tempbytes byte PHP keyLen

byte[] ctxbytes = System.Text.Encoding.UTF8.GetBytes(ctx);
byte[] keybytes = System.Text.Encoding.UTF8.GetBytes(key);
int ctxLen = ctxbytes.Length;
int keyLen = keybytes.Length;
byte[] tempbytes = new byte[ctxLen];
int index = 0;
for (int i = 0; i < ctxbytes.Length; i++)
{
if (index == keyLen)
{
index = 0;
}
tempbytes[i] = (byte)(ctxbytes[i] ^ keybytes[index]);
index++;
}
return System.Text.Encoding.UTF8.GetString(tempbytes, 0, tempbytes.Length);



 

$temp = "";
$ctxLen = strlen($ctx);
$keyLen = strlen($key);
$index = 0;
for ($i=0;$i<$ctxLen;$i++) {
if ($index == $keyLen) {
$index = 0;
}
$temp .= $ctx[$i] ^ $key[$index];
$index++;
}
return $temp;

 

标签:index,C#,加解密,int,Length,tempbytes,byte,PHP,keyLen
From: https://blog.51cto.com/kenkao/5991656

相关文章