internal SafeByte( IFastEncryptor encryptor, IFastRandom fastRandom, IByteIdGenerator byteIdGenerator, IByteArrayProtector memoryProtector) { if (encryptor == null) { throw new ArgumentNullException(nameof(encryptor)); } if (fastRandom == null) { throw new ArgumentNullException(nameof(fastRandom)); } if (byteIdGenerator == null) { throw new ArgumentNullException(nameof(fastRandom)); } if (memoryProtector == null) { throw new ArgumentNullException(nameof(memoryProtector)); } _encryptor = encryptor; _fastRandom = fastRandom; _byteIdGenerator = byteIdGenerator; _memoryProtector = memoryProtector; }
public AesEncryptor(IKeyDerivationFunction keyDeriver, IFastRandom fastRandom) : base(fastRandom) { if (keyDeriver == null) { throw new ArgumentNullException(nameof(keyDeriver)); } _keyDeriver = keyDeriver; }
internal SafeByte( IFastEncryptor encryptor, IFastRandom fastRandom, IByteIdGenerator byteIdGenerator, IMemoryProtectedBytes encryptedByte, IMemoryProtectedBytes encryptionKey) { _encryptor = encryptor ?? throw new ArgumentNullException(nameof(encryptor)); _fastRandom = fastRandom ?? throw new ArgumentNullException(nameof(fastRandom)); _byteIdGenerator = byteIdGenerator ?? throw new ArgumentNullException(nameof(fastRandom)); _encryptedByte = encryptedByte ?? throw new ArgumentNullException(nameof(encryptedByte)); _encryptionKey = encryptionKey ?? throw new ArgumentNullException(nameof(encryptionKey)); }
internal bool[][] SetRandomCells(IFastRandom randomiser, int size) { var cells = new bool[size][]; for (int y = 0; y < size; ++y) { cells[y] = new bool[size]; for (int x = 0; x < size; ++x) { cells[y][x] = randomiser.NextBoolean(); } } return(cells); }
/// <summary> /// Private constructor for creating identical instance of the <see cref="SafeByte" />. /// </summary> private SafeByte( int id, int realBytePosition, int encryptedByteLength, IFastEncryptor encryptor, IFastRandom fastRandom, IByteIdGenerator byteIdGenerator, IMemoryProtectedBytes encryptedByte, IMemoryProtectedBytes encryptionKey) { _encryptor = encryptor; _fastRandom = fastRandom; _byteIdGenerator = byteIdGenerator; //Deep copy _id = id; _realBytePosition = realBytePosition; _encryptedByte = encryptedByte.DeepClone(); _encryptionKey = encryptionKey.DeepClone(); _encryptedByteLength = encryptedByteLength; IsByteSet = true; }
internal EncryptedSafeByteCollection(IFastEncryptor encryptor, IByteArrayProtector memoryProtector, IFastRandom fastRandom, ISafeByteFactory safeByteFactory) { if (encryptor == null) { throw new ArgumentNullException(nameof(encryptor)); } if (memoryProtector == null) { throw new ArgumentNullException(nameof(memoryProtector)); } if (safeByteFactory == null) { throw new ArgumentNullException(nameof(safeByteFactory)); } _encryptor = encryptor; _memoryProtector = memoryProtector; _safeByteFactory = safeByteFactory; _encryptionKey = fastRandom.GetBytes(_memoryProtector.BlockSizeInBytes); _memoryProtector.Protect(_encryptionKey); }
internal SafeBytes( IFastRandom fastRandom, ISafeByteFactory safeByteFactory, IFactory <ISafeBytes> safeBytesFactory, IFactory <ISafeByteCollection> safeByteCollectionFactory) { if (fastRandom == null) { throw new ArgumentNullException(nameof(fastRandom)); } if (safeByteFactory == null) { throw new ArgumentNullException(nameof(safeByteFactory)); } if (safeBytesFactory == null) { throw new ArgumentNullException(nameof(safeBytesFactory)); } _fastRandom = fastRandom; _safeByteFactory = safeByteFactory; _safeBytesInstantiator = safeBytesFactory; _safeByteCollection = safeByteCollectionFactory.Create(); }
/// <summary> /// Private constructor for creating identical instance of the <see cref="SafeByte" />. /// </summary> private SafeByte( int id, int realBytePosition, int encryptedByteLength, byte[] encryptionKey, byte[] encryptedByte, IFastEncryptor encryptor, IFastRandom fastRandom, IByteIdGenerator byteIdGenerator, IByteArrayProtector memoryProtector) { _encryptor = encryptor; _fastRandom = fastRandom; _byteIdGenerator = byteIdGenerator; _memoryProtector = memoryProtector; //Deep copy _id = id; _realBytePosition = realBytePosition; _encryptedByte = new byte[encryptedByte.Length]; _encryptionKey = new byte[encryptionKey.Length]; Buffer.BlockCopy(encryptedByte, 0, _encryptedByte, 0, encryptedByte.Length); Buffer.BlockCopy(encryptionKey, 0, _encryptionKey, 0, encryptionKey.Length); _memoryProtector.Protect(_encryptionKey); _memoryProtector.Protect(_encryptedByte); _encryptedByteLength = encryptedByteLength; IsByteSet = true; }
private static IByteArrayProtector GetSut(IFastEncryptor encryptor = null, IFastRandom random = null) => new MemoryProtector( encryptor: encryptor ?? Stubs.Get <IFastEncryptor>(), random: random ?? Stubs.Get <IFastRandom>());
protected ISafeEncryptor GetSut(IKeyDerivationFunction kdf = null, IFastRandom random = null) { return(new AesEncryptor(kdf ?? Stubs.Get <IKeyDerivationFunction>(), random ?? Stubs.Get <IFastRandom>())); }
internal BlowfishInternal(IFastRandom fastRandom) { _random = fastRandom; }