Ejemplo n.º 1
0
        public static T Deserialize <T>(string base64EncryptedXmlString, KeyVectorPair key)
        {
            RijndaelManaged rKey = new RijndaelManaged();

            rKey.IV  = Convert.FromBase64String(key.IV);
            rKey.Key = Convert.FromBase64String(key.Key);

            string xml = Decrypt(base64EncryptedXmlString, key.Key, key.IV);

            return(SerializationUtil.FromXmlString <T>(xml));
        }
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 KeyVectorPair key)
        {
            string          xml = SerializationUtil.GetXml(target);
            RijndaelManaged rm  = new RijndaelManaged();

            rm.GenerateIV();
            rm.GenerateKey();
            key     = new KeyVectorPair();
            key.Key = Convert.ToBase64String(rm.Key);
            key.IV  = Convert.ToBase64String(rm.IV);
            return(Encrypt(xml, rm.CreateEncryptor()));
        }
Ejemplo n.º 3
0
        public static T Decrypt <T>(string filePath, string keyFile)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(string.Format("The file specied to deserialize from {0} does not exist", filePath));
            }

            if (!File.Exists(keyFile))
            {
                throw new FileNotFoundException(string.Format("The key file specified {0} does not exist", keyFile));
            }

            KeyVectorPair key = KeyVectorPair.Load(keyFile); //Serialization.Deserialize<Base64EncodedRijndaelKeyVectorPair>(keyFile);

            using (StreamReader sr = new StreamReader(filePath))
            {
                string text = sr.ReadToEnd();
                return(Deserialize <T>(text, key));
            }
        }
Ejemplo n.º 4
0
 public static string Decrypt(string base64EncodedValue, KeyVectorPair key)
 {
     return(Decrypt(base64EncodedValue, key.Key, key.IV));
 }
Ejemplo n.º 5
0
 public static string Encrypt(string value, KeyVectorPair key)
 {
     return(Encrypt(value, key.Key, key.IV));
 }