static void Main(string[] args) { var randomCharsGenerator = new RandomCharsGenerator(); var randomBytesGenerator = new RandomBytesGenerator(); randomCharsGenerator.GenerateFiles(1, 20); randomBytesGenerator.GenerateFiles(2, 50); }
public static void Main(string[] args) { RandomCharGenerator Char = new RandomCharGenerator(); RandomBytesGenerator Bytes = new RandomBytesGenerator(); Char.GenerateFiles(2, 3); Bytes.GenerateFiles(2, 3); }
static void Main(string[] args) { RandomCharsGenerator charsGenerator = new RandomCharsGenerator(); RandomBytesGenerator bytesGenerator = new RandomBytesGenerator(); charsGenerator.GenerateFiles(1, 10); bytesGenerator.GenerateFiles(2, 30); }
public void Test_Encrypt_WithAdditionalData_ReturnsNonZeroOutput() { using (var key = XChaChaKey.Generate()) { var aeadCipher = new XChaChaAeadCipher(); var nonce = XChaChaNonce.Generate(); var additionalData = Encoding.UTF8.GetBytes(DateTime.Now.ToString()); var message = RandomBytesGenerator.NextBytes(1024 * 1024); var ciphertext = aeadCipher.Encrypt(message, key, nonce, additionalData); Assert.False(ciphertext.All(b => b == 0)); } }
public void Test_Decrypt_ReturnsMessage(Type cipherType) { using (var key = XChaChaKey.Generate()) { var cipher = (XChaChaSecretKeyCipher)Activator.CreateInstance(cipherType); var nonce = XChaChaNonce.Generate(); const int messageLength = 1024 * 1024; var message = RandomBytesGenerator.NextBytes(messageLength); var ciphertext = cipher.Encrypt(message, key, nonce); var result = cipher.Decrypt(ciphertext, key, nonce); Assert.Equal(message, result); } }
public void Test_Decrypt_WithAdditionalData_Success() { using (var key = XChaChaKey.Generate()) { var aeadCipher = new XChaChaAeadCipher(); var nonce = XChaChaNonce.Generate(); var additionalData = Encoding.UTF8.GetBytes(DateTime.Now.ToString()); const int messageLength = 1024 * 1024; var message = RandomBytesGenerator.NextBytes(messageLength); var ciphertext = aeadCipher.Encrypt(message, key, nonce, additionalData); var result = aeadCipher.Decrypt(ciphertext, key, nonce, additionalData); Assert.Equal(message, result); } }
public void Test_TryDecrypt_Fails_ReturnsFalse(Type cipherType) { using (var key = XChaChaKey.Generate()) { var cipher = (XChaChaSecretKeyCipher)Activator.CreateInstance(cipherType); var nonce = XChaChaNonce.Generate(); const int messageLength = 1024 * 1024; var message = RandomBytesGenerator.NextBytes(messageLength); var ciphertext = new byte[cipher.GetCipherTextLength(message.Length)]; cipher.Encrypt(message, ciphertext, key, nonce); var wrongNonce = XChaChaNonce.Generate(); var result = cipher.TryDecrypt(ciphertext, ciphertext, key, wrongNonce); Assert.False(result); } }
public void Test_TryDecrypt_CanDecryptCiphertext(Type cipherType) { using (var key = XChaChaKey.Generate()) { var cipher = (XChaChaSecretKeyCipher)Activator.CreateInstance(cipherType); var nonce = XChaChaNonce.Generate(); const int messageLength = 1024 * 1024; var message = RandomBytesGenerator.NextBytes(messageLength); var ciphertext = new byte[cipher.GetCipherTextLength(message.Length)]; cipher.Encrypt(message, ciphertext, key, nonce); var decryptedMessage = new byte[messageLength]; var result = cipher.TryDecrypt(ciphertext, decryptedMessage, key, nonce); Assert.True(result); Assert.Equal(message, decryptedMessage); } }
public void Test_Decrypt_WithInvalidAdditionalData_Fails() { using (var key = XChaChaKey.Generate()) { var aeadCipher = new XChaChaAeadCipher(); var nonce = XChaChaNonce.Generate().ToArray(); var additionalData = Encoding.UTF8.GetBytes(DateTime.Now.ToString()); const int messageLength = 1024 * 1024; var message = RandomBytesGenerator.NextBytes(messageLength); var ciphertext = aeadCipher.Encrypt(message, key, new XChaChaNonce(nonce), additionalData); var invalidAdditionalData = Encoding.UTF8.GetBytes("banana"); Action action = () => { aeadCipher.Decrypt(ciphertext, key, new XChaChaNonce(nonce), invalidAdditionalData); }; var exception = Assert.Throws <CryptographicException>(action); Assert.Equal("decryption failed", exception.Message); } }
public void Test_Decrypt_Fails_ThrowsCryptographicException(Type cipherType) { using (var key = XChaChaKey.Generate()) { var cipher = (XChaChaSecretKeyCipher)Activator.CreateInstance(cipherType); var nonce = XChaChaNonce.Generate(); const int messageLength = 1024 * 1024; var message = RandomBytesGenerator.NextBytes(messageLength); var ciphertext = new byte[cipher.GetCipherTextLength(message.Length)]; cipher.Encrypt(message, ciphertext, key, nonce); Action action = () => { var wrongNonce = XChaChaNonce.Generate(); cipher.Decrypt(ciphertext, ciphertext, key, wrongNonce); }; var exception = Assert.Throws <CryptographicException>(action); Assert.Equal("decryption failed", exception.Message); } }