Ejemplo n.º 1
0
        /// <summary>
        /// Decrypts the specified instance byte array.
        /// </summary>
        /// <param name="instanceArray">Instance byte array submitted for decryption.</param>
        /// <returns>Object if decryption was successful; null for otherwise.</returns>
        public static object Decrypt(byte[] instanceArray)
        {
            if (instanceArray == null || instanceArray.LongLength == 0)
            {
                Logger.Warn("Unable to decrypt null or empty byte array!");
                return(null);
            }

            if (Logger.IsDebugEnabled)
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                Logger.DebugFormat("Decrypting instance: {0}", encoding.GetString(instanceArray));
            }

            byte[] decryptedInstance;

            try
            {
                decryptedInstance = SimpleEncryption.Decrypt(instanceArray, PassPhrase);
            }
            catch (Exception exception)
            {
                Logger.Error("Problem encountered decrypting the byte array!", exception);
                return(null);
            }

            return(ObjectUtil.ConvertToObject(decryptedInstance));
        }
Ejemplo n.º 2
0
        public void TestSerializeComplexObjectGood()
        {
            Parent parent = new Parent {
                Name = "Hello", Child = new Child {
                    Name = "World"
                }
            };

            byte[] serialized = ObjectUtil.ConvertToByteArray(parent);

            Assert.NotNull(serialized);
            Assert.IsTrue(serialized.LongLength > 0);
            Assert.AreEqual(372, serialized.LongLength);

            Parent deserialized = (Parent)ObjectUtil.ConvertToObject(serialized);

            Assert.NotNull(deserialized);
            Assert.AreEqual("Hello", deserialized.Name);
            Assert.AreEqual("World", deserialized.Child.Name);
        }
Ejemplo n.º 3
0
        public void TestBoundaryConvertToObject()
        {
            Assert.Null(ObjectUtil.ConvertToObject(null));

            Assert.Null(ObjectUtil.ConvertToObject(new byte[] { 1, 2, 3, 4 }));
        }