Пример #1
0
        private byte[] ApplyProperDeciphering(byte[] receiveBuffer)
        {
            try
            {
                switch (State)
                {
                case (ProtocolState.WaitingSession):
                    List <string> targetFields = new List <string> {
                        "key", "iv"
                    };
                    XmlDocument document = ConvertUtils.ByteArrayToXMLDocument(receiveBuffer);
                    return(ConvertUtils.XmlDocumentToByteArray(RsaUtils.DecipherXmlDocument(document, GetDefaultKeyContainer(), targetFields)));

                case (ProtocolState.GotSession):
                    return(AESUtils.DecipherByteArray(receiveBuffer, server.GetSessionKey(), server.GetNextIV()));

                case (ProtocolState.GotSecret):
                    return(AESUtils.DecipherByteArray(receiveBuffer, server.GetSessionKey(), server.GetNextIV()));

                case (ProtocolState.FailOnce):
                    return(AESUtils.DecipherByteArray(receiveBuffer, server.GetSessionKey(), server.GetNextIV()));

                case (ProtocolState.FailTwice):
                    return(AESUtils.DecipherByteArray(receiveBuffer, server.GetSessionKey(), server.GetNextIV()));

                default:
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }