Exemplo n.º 1
0
        public _T Deserialize <_T>(object serializedData)
        {
            _T result;

            {
                byte[][] array = this.myUnderlyingSerializer.Deserialize <byte[][]>(serializedData);
                RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider();
                rSACryptoServiceProvider.ImportParameters(this.myPrivateKey);
                byte[]        key           = rSACryptoServiceProvider.Decrypt(array[0], false);
                byte[]        iv            = rSACryptoServiceProvider.Decrypt(array[1], false);
                AesSerializer aesSerializer = new AesSerializer(key, iv, this.myUnderlyingSerializer);
                _T            t             = aesSerializer.Deserialize <_T>(array[2]);
                result = t;
            }
            return(result);
        }
Exemplo n.º 2
0
        public object Serialize <_T>(_T dataToSerialize)
        {
            object result;

            {
                byte[][]   array      = new byte[3][];
                AesManaged aesManaged = new AesManaged();
                aesManaged.KeySize = this.myAesBitSize;
                aesManaged.GenerateIV();
                aesManaged.GenerateKey();
                AesSerializer aesSerializer = new AesSerializer(aesManaged.Key, aesManaged.IV, this.myUnderlyingSerializer);
                array[2] = (byte[])aesSerializer.Serialize <_T>(dataToSerialize);
                RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider();
                rSACryptoServiceProvider.ImportParameters(this.myPublicKey);
                array[0] = rSACryptoServiceProvider.Encrypt(aesManaged.Key, false);
                array[1] = rSACryptoServiceProvider.Encrypt(aesManaged.IV, false);
                object obj = this.myUnderlyingSerializer.Serialize <byte[][]>(array);
                result = obj;
            }
            return(result);
        }