Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#中的加密和C(QNX操作系统)中的解密_C#_C++_C_Encryption_Qnx - Fatal编程技术网

C#中的加密和C(QNX操作系统)中的解密

C#中的加密和C(QNX操作系统)中的解密,c#,c++,c,encryption,qnx,C#,C++,C,Encryption,Qnx,我正在尝试使用Security.Cryptography库在C#platform中加密消息。请在下面查找代码 using (AuthenticatedAesCng aes = new AuthenticatedAesCng()) { byte[] message = Encoding.UTF8.GetBytes(s); // Convert to bytes. aes.Key = getEncryptionKey();

我正在尝试使用Security.Cryptography库在C#platform中加密消息。请在下面查找代码

using (AuthenticatedAesCng aes = new AuthenticatedAesCng())
{
    byte[] message = Encoding.UTF8.GetBytes(s);                   // Convert to bytes.
    aes.Key = getEncryptionKey();                                   // Retrieve Key.
    aes.IV = generateIV();                                          // Generate nonce.
    aes.CngMode = CngChainingMode.Gcm;                              // Set Cryptographic Mode.
    aes.AuthenticatedData = getAdditionalAuthenticationData();     // Set Authentication Data.
    byte[] encrypted;

    using (MemoryStream ms = new MemoryStream())
    {
        using (IAuthenticatedCryptoTransform encryptor = aes.CreateAuthenticatedEncryptor())
        {
            using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
            {
                // Write through and retrieve encrypted data.
                cs.Write(message, 0, message.Length);
                cs.FlushFinalBlock();
                byte[] cipherText = ms.ToArray();

                // Retrieve tag and create array to hold encrypted data.
                byte[] authenticationTag = encryptor.GetTag();
                encrypted = new byte[cipherText.Length + aes.IV.Length + authenticationTag.Length];

                // Set needed data in byte array.
                aes.IV.CopyTo(encrypted, 0);
                authenticationTag.CopyTo(encrypted, IV_LENGTH);
                cipherText.CopyTo(encrypted, IV_LENGTH + TAG_LENGTH);
            }
        }
    }  
} 

// Store encrypted value in base 64.
// Convert.ToBase64String(encrypted);

lock (SnmpUdpClient.Client)
{
    nRet = SnmpUdpClient.Client.Send(encrypted, idx, gaddr.IPEndPoint);
}
我通过UDP连接将加密数据包发送到客户端。客户端应接收加密数据,并使用C/C++平台(QNX OS)对其进行解密


有人能帮我理解怎么做吗。C/C++或QNX是否有可用于实现相同功能的库。

您的
Send()
位置错误,请先关闭所有流。将其向下移动几下。。按建议进行更改。再编辑一点。现在它是伪代码,您需要保留对memorystream的引用,以便在usings之外使用。我可以将加密数据包发送到客户端。我可以在客户端看到数据包。我在解密数据包时遇到了困难。客户端代码是用C/C++编写的。有人能建议在客户端使用的解密方法吗。我们将如何验证接收到的数据包。好的,但是它们的长度正确吗?始终验证。您的
Send()
位置错误,请先关闭所有流。将其向下移动几下。。按建议进行更改。再编辑一点。现在它是伪代码,您需要保留对memorystream的引用,以便在usings之外使用。我可以将加密数据包发送到客户端。我可以在客户端看到数据包。我在解密数据包时遇到了困难。客户端代码是用C/C++编写的。有人能建议在客户端使用的解密方法吗。我们将如何验证接收到的数据包。好的,但是它们的长度正确吗?始终验证。