Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously initializes the asymmetric key.
        /// </summary>
        protected async Task InitializeHashKeyAsync()
        {
            if (!IsHashKeyInitialized)
            {
                if (KeyStorage.KeyLocationExists(KeyLocation))
                {
                    DecryptHashKey(
                        await KeyStorage.GetKeyAsync(KeyLocation));
                }
                else
                {
                    await KeyStorage.PutKeyAsync(EncryptHashKey(), KeyLocation);
                }

                IsHashKeyInitialized = true;
            }

            _hashAlgorithm.Initialize();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously initializes the symmetric key for encryption.
        /// </summary>
        /// <returns>
        /// A <see cref="Task"/> object representing the process of asynchronous initialization.
        /// </returns>
        protected virtual async Task InitializeSymmetricKeyAsync()
        {
            if (IsSymmetricKeyInitialized)
            {
                return;
            }

            // get or create and put the file from/to its location
            if (KeyStorage.KeyLocationExists(KeyLocation))
            {
                DecryptSymmetricKey(await KeyStorage.GetKeyAsync(KeyLocation));
            }
            else
            {
                Symmetric.GenerateKey();
                await KeyStorage.PutKeyAsync(EncryptSymmetricKey(), KeyLocation);
            }

            IsSymmetricKeyInitialized = true;
        }