Пример #1
0
 internal EncryptedSafeByteCollection(
     IFastEncryptor encryptor,
     IMemoryProtectedBytes encryptionKey,
     ICryptoRandom fastRandom,
     ISafeByteFactory safeByteFactory,
     IByteIdListSerializer <int> serializer)
 {
     if (fastRandom == null)
     {
         throw new ArgumentNullException(nameof(fastRandom));
     }
     _encryptionKey = new AsyncLazy <IMemoryProtectedBytes>(async() =>
     {
         await encryptionKey.InitializeAsync(fastRandom.GetBytes(encryptionKey.BlockSizeInBytes))
         .ConfigureAwait(false);
         return(encryptionKey);
     });
     _encryptor       = encryptor ?? throw new ArgumentNullException(nameof(encryptor));
     _safeByteFactory = safeByteFactory ?? throw new ArgumentNullException(nameof(safeByteFactory));
     _serializer      = serializer;
     _salt            = fastRandom.GetBytes(encryptor.BlockSizeInBits / 8);
 }
Пример #2
0
        /// <summary>Create a new ECDH key pair for key exchange.</summary>
        /// <param name="random">Random number generator to use for generating keys.</param>
        /// <param name="allocator">Allocator to use for allocating keys.</param>
        public CryptoECDH(ICryptoRandom random, Allocator allocator)
        {
            // Validate
            if (allocator == null)
            {
                throw new ArgumentNullException(nameof(allocator), "No allocator");
            }

            // Initialize
            Allocator = allocator;
            Disposed  = false;

            // Generate private key
            PrivateKey = Allocator.CreateKey(32);
            random.GetBytes(PrivateKey, 0, 32);
            Curve25519.ClampPrivateKeyInline(PrivateKey);

            // Generate public key
            PublicKey = Allocator.CreateKey(32);
            Curve25519.GetPublicKeyInline(PrivateKey, PublicKey);
        }
 internal MemoryProtector(IFastEncryptor encryptor, ICryptoRandom random)
 {
     _encryptor = encryptor;
     _key       = random.GetBytes(Encryptor.MinKeySize);
 }
 /// <exception cref="ArgumentNullException"><paramref name="encryptor" /> is <see langword="null" />.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
 internal MemoryProtector(IFastEncryptor encryptor, ICryptoRandom random)
 {
     _encryptor         = encryptor ?? throw new ArgumentNullException(nameof(encryptor));
     _key               = random.GetBytes(Encryptor.MinKeySizeInBits);
     _encryptor.Padding = PaddingMode.None;
 }
Пример #5
0
 protected byte[] GetIv() => _random.GetBytes(IvSize);