Esempio n. 1
0
        /// <summary>
        /// Saves the public property values contained in the current instance to an encrypted file. Key and IV parameters are used
        /// to specify an AES encryption. Serialization is used to get the object values into an XML string that will be encrypted and
        /// written to the output file.
        /// </summary>
        /// <param name="filePath">Full path for output file.</param>
        /// <param name="key">AES encryption key.</param>
        /// <param name="iv">AES IV value.</param>
        /// <remarks>Only AES encryption is supported by this routine.</remarks>
        public void SaveToXmlFile(string filePath, string key, string iv)
        {
            pfEncryptionAlgorithm alg  = pfEncryptionAlgorithm.AES;
            IStringEncryptor      enc2 = PFEncryption.GetStringEncryptor(alg);
            //store xml data in a string
            string xmldata = this.ToXmlString();

            //encrypt the xml data string
            enc2.Key = key;
            enc2.IV  = iv;
            string encryptedXML = enc2.Encrypt(xmldata);

            //save encrypted xml to file
            File.WriteAllText(filePath, encryptedXML);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance stored in an encrypted file.
        /// The file is first decrypted into an XML string and the XML string is then used to create an instance of the class.
        /// </summary>
        /// <param name="filePath">Full path for the input file.</param>
        /// <param name="key">AES encryption key.</param>
        /// <param name="iv">AES IV value.</param>
        /// <returns>An instance of PFKeyValueListEx.</returns>
        /// <remarks>Only AES encryption is supported by this routine.</remarks>
        public static PFKeyValueListExSorted <K, V> LoadFromXmlFile(string filePath, string key, string iv)
        {
            pfEncryptionAlgorithm         alg  = pfEncryptionAlgorithm.AES;
            IStringEncryptor              enc2 = PFEncryption.GetStringEncryptor(alg);
            PFKeyValueListExSorted <K, V> listElements;

            //first: load the encrypted data from the specified file
            string encryptedXML = File.ReadAllText(filePath);

            //next: decrypt the encrypted data
            enc2.Key = key;
            enc2.IV  = iv;
            string xmldata = enc2.Decrypt(encryptedXML);

            //step 3: create a PFLIcense object from the decrypted string
            listElements = LoadFromXmlString(xmldata);
            //finally: return to caller
            return(listElements);
        }
Esempio n. 3
0
        public pfKeyIvPair GenerateKeyIVPair(pfEncryptionAlgorithm alg)
        {
            pfKeyIvPair ki = PFEncryption.GenerateKeyIvPair(alg);

            return(ki);
        }