/// <summary> /// Initializes a new instance of the <see cref="PipelinedSimpleModulusEncryptor" /> class. /// </summary> /// <param name="target">The target pipe writer.</param> /// <param name="encryptionKeys">The encryption keys.</param> public PipelinedSimpleModulusEncryptor(PipeWriter target, SimpleModulusKeys encryptionKeys) { this.target = target; this.encryptionKeys = encryptionKeys; this.Source = this.Pipe.Reader; this.ReadSource().ConfigureAwait(false); }
/// <summary> /// Initializes a new instance of the <see cref="PipelinedSimpleModulusDecryptor"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="decryptionKeys">The decryption keys.</param> public PipelinedSimpleModulusDecryptor(PipeReader source, SimpleModulusKeys decryptionKeys) : base(decryptionKeys.DecryptKey.Length == 4 ? Variant.New : Variant.Old) { this.Source = source; this.decryptionKeys = decryptionKeys; this.inputBuffer = new byte[this.EncryptedBlockSize]; this.ReadSource().ConfigureAwait(false); }
/// <summary> /// Initializes a new instance of the <see cref="PipelinedSimpleModulusEncryptor" /> class. /// </summary> /// <param name="target">The target pipe writer.</param> /// <param name="encryptionKeys">The encryption keys.</param> public PipelinedSimpleModulusEncryptor(PipeWriter target, SimpleModulusKeys encryptionKeys) : base(encryptionKeys.DecryptKey.Length == 4 ? Variant.New : Variant.Old) { this.target = target; this.encryptionKeys = encryptionKeys; this.Source = this.Pipe.Reader; this.inputBuffer = new byte[this.DecryptedBlockSize]; this.ReadSource().ConfigureAwait(false); }
/// <summary> /// Generates a new pair of keys. /// </summary> /// <returns>The generated pair of new keys.</returns> public async Task <SimpleModulusKeys> GenerateKeys() { var result = new SimpleModulusKeys(); do { for (int i = 0; i < 4; i++) { this.FindKeys(out uint xorKey, out uint modulusKey, out uint encryptKey, out uint decryptKey); result.ModulusKey[i] = modulusKey; result.DecryptKey[i] = decryptKey; result.EncryptKey[i] = encryptKey; result.XorKey[i] = xorKey; } }while (!await this.ValidateResult(result).ConfigureAwait(false)); return(result); }
/// <summary> /// Creates an instance of <see cref="SimpleModulusKeys"/> with the crypt key as <see cref="EncryptKey"/>. /// </summary> /// <param name="encryptionKey">The decryption key with 12 integers.</param> /// <returns>An instance of <see cref="SimpleModulusKeys"/> with the crypt key as <see cref="EncryptKey"/>.</returns> public static SimpleModulusKeys CreateEncryptionKeys(uint[] encryptionKey) { var keys = new SimpleModulusKeys(); keys.ModulusKey[0] = encryptionKey[0]; keys.ModulusKey[1] = encryptionKey[1]; keys.ModulusKey[2] = encryptionKey[2]; keys.ModulusKey[3] = encryptionKey[3]; keys.EncryptKey[0] = encryptionKey[4]; keys.EncryptKey[1] = encryptionKey[5]; keys.EncryptKey[2] = encryptionKey[6]; keys.EncryptKey[3] = encryptionKey[7]; keys.XorKey[0] = encryptionKey[8]; keys.XorKey[1] = encryptionKey[9]; keys.XorKey[2] = encryptionKey[10]; keys.XorKey[3] = encryptionKey[11]; return(keys); }
/// <summary> /// Generates a new pair of keys. /// </summary> /// <returns>The generated pair of new keys.</returns> public SimpleModulusKeys GenerateKeys() { var result = new SimpleModulusKeys(); do { for (int i = 0; i < 4; i++) { this.FindKeys(out uint xorKey, out uint modulusKey, out uint encryptKey, out uint decryptKey); result.ModulusKey[i] = modulusKey; result.DecryptKey[i] = decryptKey; result.EncryptKey[i] = encryptKey; result.XorKey[i] = xorKey; } }while (!this.ValidateResult(result)); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="PipelinedSimpleModulusEncryptor"/> class. /// </summary> /// <param name="target">The target pipe writer.</param> /// <param name="encryptionKeys">The encryption keys.</param> public PipelinedSimpleModulusEncryptor(PipeWriter target, uint[] encryptionKeys) : this(target, SimpleModulusKeys.CreateEncryptionKeys(encryptionKeys)) { }
private async Task <bool> ValidateResult(SimpleModulusKeys result) { return(await this.ValidateKeys(result.GetEncryptionKeys(), result.GetDecryptionKeys()).ConfigureAwait(false)); }
/// <summary> /// Initializes a new instance of the <see cref="PipelinedSimpleModulusDecryptor"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="decryptionKey">The decryption key.</param> public PipelinedSimpleModulusDecryptor(PipeReader source, uint[] decryptionKey) : this(source, SimpleModulusKeys.CreateDecryptionKeys(decryptionKey)) { }
/// <summary> /// Initializes a new instance of the <see cref="SimpleModulusEncryptor" /> class. /// </summary> /// <param name="encryptionKeys">The encryption keys.</param> public SimpleModulusEncryptor(SimpleModulusKeys encryptionKeys) { this.encryptionKeys = encryptionKeys; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleModulusEncryptor"/> class. /// </summary> /// <param name="encryptionKey">The encryption key.</param> public SimpleModulusEncryptor(uint[] encryptionKey) : this(SimpleModulusKeys.CreateEncryptionKeys(encryptionKey)) { }
/// <summary> /// Initializes a new instance of the <see cref="SimpleModulusDecryptor"/> class. /// </summary> /// <param name="decryptionKeys">The decryption keys.</param> public SimpleModulusDecryptor(SimpleModulusKeys decryptionKeys) { this.decryptionKeys = decryptionKeys; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleModulusDecryptor"/> class. /// </summary> /// <param name="decryptionKey">The decryption key.</param> public SimpleModulusDecryptor(uint[] decryptionKey) : this(SimpleModulusKeys.CreateDecryptionKeys(decryptionKey)) { }
private bool ValidateResult(SimpleModulusKeys result) { return(this.ValidateKeys(result.GetEncryptionKeys(), result.GetDecryptionKeys())); }
/// <summary> /// Initializes a new instance of the <see cref="PipelinedSimpleModulusDecryptor"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="decryptionKeys">The decryption keys.</param> public PipelinedSimpleModulusDecryptor(PipeReader source, SimpleModulusKeys decryptionKeys) { this.Source = source; this.decryptionKeys = decryptionKeys; this.ReadSource().ConfigureAwait(false); }