Secure SSL Stream.read ...throws System.IO.IOException: The decryption operation failed (System.ComponentModel.Win32Exception: The specified data could not be decrypted)

Jeyakumar Guruchandran 1 Reputation point
2021-01-12T13:34:56.08+00:00

we are using the SSL Stream Read to receive bytes of the files from the remote machine using TCP port .we have authentication done with X509Certificate2 certifcate

for the file transfer from one machine to another.
In call back of the tcplistener, BeginAcceptTcpClient we are doing this and getting the error in sslstream.read

The decrypt failure io exception

FileTransferInfo info;
using (var tcpClient = serverListener.EndAcceptTcpClient(ar))
{
serverListener.BeginAcceptTcpClient(OnConnect, null);

                // A client has connected. Create the 
                // SslStream using the client's network stream.
                using (var sslStream = new SslStream(
                    tcpClient.GetStream(),
                    true,
                    ValidateClientCertificate,
                    null))
                {
                    sslStream.AuthenticateAsServer(this.serverCertificate, true, SslProtocols.Tls12, false);

                    var bytes = new byte[sizeof(int)];
                    try
                    {
                        sslStream.Read(bytes, 0, sizeof(int));

Please help us it is happening very randomly .. not everytime

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,166 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.