public void roundTrip()
        {
            EncryptMessage msg = new EncryptMessage();

            msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, true);
            msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), false);
            msg.SetContent(strContent);
            msg.Encrypt(rgbKey128);
            byte[] rgbMsg = msg.EncodeToBytes();

            msg = (EncryptMessage)Message.DecodeFromBytes(rgbMsg);
            msg.Decrypt(rgbKey128);

            Assert.AreEqual <string>(msg.GetContentAsString(), strContent);
        }
Пример #2
0
        public void roundTrip()
        {
            EncryptMessage msg = new EncryptMessage();

            msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED);
            msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.UNPROTECTED);
            msg.SetContent(strContent);
            Recipient r = new Recipient(key128, AlgorithmValues.Direct);

            msg.AddRecipient(r);
            msg.Encrypt();
            byte[] rgbMsg = msg.EncodeToBytes();

            msg = (EncryptMessage)Message.DecodeFromBytes(rgbMsg);
            r   = msg.RecipientList[0];
            r.SetKey(key128);
            msg.Decrypt(r);

            Assert.AreEqual <string>(msg.GetContentAsString(), strContent);
        }
Пример #3
0
        static void CheckMessage(Message msg, JWK key, CBORObject input)
        {
            if (msg.GetType() == typeof(EncryptMessage))
            {
                EncryptMessage enc = (EncryptMessage)msg;

                Recipient recipient = enc.RecipientList[0];
                recipient.SetKey(key);

                try {
                    enc.Decrypt(recipient);
                }
                catch (Exception e) { Console.WriteLine("Failed to decrypt " + e.ToString()); return; }

                if (enc.GetContentAsString() != input["plaintext"].AsString())
                {
                    Console.WriteLine("Plain text does not match");
                }
            }
            else if (msg.GetType() == typeof(SignMessage))
            {
                SignMessage sig = (SignMessage)msg;

                try {
                    try {
                        sig.GetContentAsString();
                    }
                    catch (System.Exception) {
                        sig.SetContent(input["payload"].AsString());
                    }
                    sig.Validate(key);

                    if (sig.GetContentAsString() != input["payload"].AsString())
                    {
                        Console.WriteLine("Plain text does not match");
                    }
                }
                catch (Exception e) { Console.WriteLine("Failed to verify " + e.ToString()); return; }
            }
        }
Пример #4
0
        static void CheckMessage(Message msg, Key key, JSON input)
        {
            if (msg.GetType() == typeof(EncryptMessage))
            {
                EncryptMessage enc = (EncryptMessage)msg;

                try {
                    enc.Decrypt(key);
                }
                catch (Exception e) { Console.WriteLine("Failed to decrypt " + e.ToString()); return; }

                if (enc.GetContentAsString() != input["plaintext"].AsString())
                {
                    Console.WriteLine("Plain text does not match");
                }
            }
            else if (msg.GetType() == typeof(SignMessage))
            {
                SignMessage sig = (SignMessage)msg;

                try {
                    try {
                        sig.GetContentAsString();
                    }
                    catch (System.Exception) {
                        sig.SetContent(input["payload"].AsString());
                    }
                    sig.Verify(key);

                    if (sig.GetContentAsString() != input["payload"].AsString())
                    {
                        Console.WriteLine("Plain text does not match");
                    }
                }
                catch (Exception e) { Console.WriteLine("Failed to verify " + e.ToString()); return; }
            }
        }