Пример #1
0
        /// <summary>
        /// Creates instance from encrypted data.
        /// </summary>
        /// <param name="encryptedData">Encrypted data to be decrypted.</param>
        /// <param name="entropy">Entropy to be used on decryption.</param>
        /// <param name="scope"><see cref="DataProtectionScope"/> for encrypted data.</param>
        /// <returns>ProtectedString instance.</returns>
        public static LocalProtectedString FromEncryptedData(byte[] encryptedData, byte[] entropy, DataProtectionScope scope = DataProtectionScope.CurrentUser)
        {
            var ps = new LocalProtectedString(scope);

            ps.EncryptedData = encryptedData;
            ps.Entropy       = entropy;

            return(ps);
        }
Пример #2
0
        /// <summary>
        /// Creates instance from char array.
        /// </summary>
        /// <param name="chars">Char array to be encrypted.</param>
        /// <param name="entropy">Entropy to be used on encrypting.</param>
        /// <param name="scope"><see cref="DataProtectionScope"/> for encrypted data.</param>
        /// <returns>ProtectedString instance.</returns>
        public static LocalProtectedString FromChars(char[] chars, byte[] entropy, DataProtectionScope scope = DataProtectionScope.CurrentUser)
        {
            var ps = new LocalProtectedString(scope);

            ps.Entropy = entropy;

            ps.EncryptedData = ProtectedData.Protect(
                ENCODING.GetBytes(chars),
                ps.Entropy,
                scope);

            return(ps);
        }