コード例 #1
0
        /// <inheritdoc />
        /// <inheritdoc cref="EnsureParameter" />
        public async Task ProtectAsync(byte[] userData)
        {
            this.EnsureParameter(userData);
            var encryptedBytes = await _encryptor.EncryptAsync(userData, _key)
                                 .ConfigureAwait(false);

            SetBytesToByteArray(
                source: encryptedBytes,
                target: ref userData);
        }
コード例 #2
0
        private async Task <byte[]> EncryptAsync(byte[] plainBytes, byte[] saltBytes, byte[] encryptionKey)
        {
            var salted = plainBytes.Combine(saltBytes);

            try
            {
                return(await _encryptor.EncryptAsync(salted, encryptionKey)
                       .ConfigureAwait(false));
            }
            finally
            {
                if (salted != null)
                {
                    Array.Clear(salted, 0, salted.Length);
                }
            }
        }