コード例 #1
0
        public List <Message> GetDecryptedMessagesWithPrivateKey(string token, string privateKey)
        {
            var db      = new CryptAByteContext();
            var request = db.Keys.Include("Messages").SingleOrDefault(key => key.KeyToken == token);
            var crypto  = new AsymmetricCryptoProvider();

            if (!request.IsReleased)
            {
                throw new ArgumentOutOfRangeException("Request is not released");
            }

            var plaintextMessages = new List <Message>();

            if (request.Messages != null)
            {
                request.Messages.ToList().ForEach(retrievedMessage =>
                {
                    string messageDecryptionKey;

                    var decryptedMessage = crypto.DecryptMessageWithKey(privateKey, retrievedMessage.MessageData,
                                                                        retrievedMessage.EncryptionKey,
                                                                        retrievedMessage.MessageHash, out messageDecryptionKey);

                    retrievedMessage.MessageData   = decryptedMessage;
                    retrievedMessage.EncryptionKey = messageDecryptionKey;


                    if (!retrievedMessage.IsFile)
                    {
                        retrievedMessage.MessageData =
                            GzipCompression.Decompress(retrievedMessage.MessageData);
                    }
                    else
                    {
                        // this is a zip file
                    }

                    plaintextMessages.Add(retrievedMessage);
                });

                if (request.DeleteMessagesAfterReading || request.DeleteKeyAfterReading)
                {
                    if (request.DeleteMessagesAfterReading || request.DeleteKeyAfterReading)
                    {
                        request.Messages.ToList().ForEach(message => db.Messages.Remove(message));
                    }

                    if (request.DeleteKeyAfterReading)
                    {
                        db.Keys.Remove(request);
                    }

                    db.SaveChanges();
                }
            }



            return(plaintextMessages);
        }
コード例 #2
0
        private void HandleIncomingData(byte[] data)
        {
            var stringData      = Encoding.ASCII.GetString(data);
            var handRelatedData = XmlSerialize.Deserialize <HandRelatedDataContainer>(IsDataGzipCompressed
                ? GzipCompression.Decompress(stringData)
                : stringData);

            switch (handRelatedData.HandRelatedData)
            {
            case HandRelatedData.Hand:
                var handData = handRelatedData.HandData;
                if (handData.Step == OVRPlugin.Step.Render)
                {
                    if (handData.Hand == OVRPlugin.Hand.HandLeft)
                    {
                        _lastLeftHandRenderUpdateDataToProcess = handData;
                    }
                    if (handData.Hand == OVRPlugin.Hand.HandRight)
                    {
                        _lastRightHandRenderUpdateDataToProcess = handData;
                    }
                }

                if (handData.Step == OVRPlugin.Step.Physics)
                {
                    if (handData.Hand == OVRPlugin.Hand.HandLeft)
                    {
                        _lastLeftHandPhysicsUpdateDataToProcess = handData;
                    }
                    if (handData.Hand == OVRPlugin.Hand.HandRight)
                    {
                        _lastRightHandPhysicsUpdateDataToProcess = handData;
                    }
                }
                break;

            case HandRelatedData.Skeleton:
                _skeletonUpdateDataToProcess.Enqueue(handRelatedData.SkeletonData);
                break;

            case HandRelatedData.Mesh:
                _meshUpdateDataToProcess.Enqueue(handRelatedData.MeshData);
                break;


            case HandRelatedData.Unknown:
            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #3
0
        public SelfDestructingMessage GetMessage(int messageId, string passphrase)
        {
            var db = new CryptAByteContext();

            SelfDestructingMessage message = db.SelfDestructingMessages.SingleOrDefault(m => m.MessageId == messageId);

            //.Include("SelfDestructingMessageAttachment")

            if (message == null)
            {
                throw new ArgumentOutOfRangeException("messageId", "Message not found.  Was it already read?");
            }

            var crypto = new SymmetricCryptoProvider();


            try
            {
                message.Message = crypto.DecryptWithKey(message.Message, passphrase);

                var attachment = db.SelfDestructingMessageAttachments.FirstOrDefault(a => a.MessageId == messageId);

                if (attachment != null)
                {
                    message.HasAttachment = true;
                    // todo: get filename here
                }
            }
            catch (Exception)
            {
                throw new ArgumentOutOfRangeException("passphrase", "server error decrypting message");
            }

            message.Message = GzipCompression.Decompress(message.Message);

            db.SelfDestructingMessages.Remove(message);
            db.SaveChanges();

            message.SelfDestructingMessageAttachment = new SelfDestructingMessageAttachment
            {
                //   AttachmentName = attachmentName
            };

            return(message);
        }
コード例 #4
0
        public override IElectionContext CreateElectionContext(IByteArray compressedContext)
        {
            GzipCompression compressor = new GzipCompression();

            IByteArray decompressedContext = compressor.Decompress(compressedContext);

            IDataRehydrator electionContextRehydrator = DataSerializationFactory.CreateRehydrator(decompressedContext);

            var version = electionContextRehydrator.RehydrateRewind <ComponentVersion <ElectionContextType> >();

            IElectionContext context = null;

            if (version.Type == ElectionContextTypes.Instance.Active)
            {
                if (version == (1, 0))
                {
                    context = new NeuraliumActiveElectionContext();
                }
            }

            if (version.Type == ElectionContextTypes.Instance.Passive)
            {
                if (version == (1, 0))
                {
                    context = new NeuraliumPassiveElectionContext();
                }
            }

            if (context == null)
            {
                throw new ApplicationException("Unrecognized election context version.");
            }

            context.Rehydrate(electionContextRehydrator, this);

            decompressedContext.Return();

            return(context);
        }