コード例 #1
0
        public static void Encrypt_And_Decrypt_Return_Input()
        {
            var expectedText = "Hello!";
            var key          = AesGcmCrypto.PasswordToKey(
                "secret",
                AesGcmCrypto.GenerateSalt(),
                AesGcmCrypto.Iterations);

            var cipherText = AesGcmCrypto.Encrypt(
                AesGcmCrypto.GenerateNonce(),
                Encoding.UTF8.GetBytes(expectedText),
                key);

            var actualText = Encoding.UTF8.GetString(
                AesGcmCrypto.Decrypt(cipherText, key));

            Assert.Equal(expectedText, actualText);
        }
コード例 #2
0
        private IReadOnlyCollection <Uri> WriteContent(
            byte[] nonce,
            Stream stream)
        {
            Uri WriteChunk(byte[] chunk)
            {
                var encryptedData = AesGcmCrypto.Encrypt(
                    nonce,
                    chunk,
                    _key.Value);

                var contentUri = Id.ComputeContentUri(
                    _hashAlgorithmName,
                    encryptedData);

                _uriRepository.StoreValue(contentUri, encryptedData);

                return(contentUri);
            }

            var expectedChunks = stream.Length / _fastCdc.AvgSize;

            if (expectedChunks < _parallelizeChunkThreshold)
            {
                return(_fastCdc.SplitIntoChunks(stream)
                       .Select(WriteChunk)
                       .ToArray());
            }
            else
            {
                return(_fastCdc.SplitIntoChunks(stream)
                       .AsParallel()
                       .AsOrdered()
                       .Select(WriteChunk)
                       .ToArray());
            }
        }