Ejemplo n.º 1
0
        public void Save(string filePath)
        {
            string xml = SerializationExtensions.ToXml(this);

            byte[] xmlBytes  = Encoding.UTF8.GetBytes(xml);
            string xmlBase64 = Convert.ToBase64String(xmlBytes);

            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.Write(xmlBase64);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a base64 encoded encrypted xml serialization string representing the specified target object
        /// </summary>
        /// <param name="target">The object to serialize</param>
        /// <param name="key">The key used to encrypt and decrypt the resulting string</param>
        /// <returns>string</returns>
        public static string ToBase64EncodedEncryptedXml(this object target, out AesKeyVectorPair key)
        {
            string     xml = SerializationExtensions.ToXml(target);
            AesManaged rm  = new AesManaged();

            rm.GenerateIV();
            rm.GenerateKey();
            key     = new AesKeyVectorPair();
            key.Key = Convert.ToBase64String(rm.Key);
            key.IV  = Convert.ToBase64String(rm.IV);
            return(Encrypt(xml, rm.CreateEncryptor()));
        }