Renamed methods

This commit is contained in:
Thorsten Sommer 2020-01-05 21:41:41 +01:00
parent 9640c7579f
commit 36001d0f70
4 changed files with 40 additions and 40 deletions

View File

@ -19,10 +19,10 @@ namespace Encrypter_Tests
var message = "This is a test with umlauts äüö.";
var password = "test password";
var encryptedData = await CryptoProcessor.EncryptString(message, password);
var encryptedData = await CryptoProcessor.Encrypt(message, password);
Assert.That(encryptedData.Length, Is.AtLeast(message.Length)); // Note: Encrypted data contains salt as well!
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password);
var decryptedMessage = await CryptoProcessor.Decrypt(encryptedData, password);
Assert.That(decryptedMessage, Is.EqualTo(message));
}
@ -32,8 +32,8 @@ namespace Encrypter_Tests
var message = string.Empty;
var password = "test password";
var encryptedData = await CryptoProcessor.EncryptString(message, password);
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password);
var encryptedData = await CryptoProcessor.Encrypt(message, password);
var decryptedMessage = await CryptoProcessor.Decrypt(encryptedData, password);
Assert.That(decryptedMessage, Is.EqualTo(message));
}
@ -45,7 +45,7 @@ namespace Encrypter_Tests
try
{
var encryptedData = await CryptoProcessor.EncryptString(message, password);
var encryptedData = await CryptoProcessor.Encrypt(message, password);
Assert.Fail("Should not be reached!");
}
catch(CryptographicException e)
@ -62,7 +62,7 @@ namespace Encrypter_Tests
try
{
var encryptedData = await CryptoProcessor.EncryptString(message, password);
var encryptedData = await CryptoProcessor.Encrypt(message, password);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -77,11 +77,11 @@ namespace Encrypter_Tests
var message = "This is a test with umlauts äüö.";
var password = "test password";
var encryptedData = await CryptoProcessor.EncryptString(message, password);
var encryptedData = await CryptoProcessor.Encrypt(message, password);
try
{
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password[..4]);
var decryptedMessage = await CryptoProcessor.Decrypt(encryptedData, password[..4]);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -96,8 +96,8 @@ namespace Encrypter_Tests
var message = Encoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII, Encoding.UTF8.GetBytes("This is a test without umlauts.")));
var password = "test password";
var encryptedData = await CryptoProcessor.EncryptString(message, password);
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password);
var encryptedData = await CryptoProcessor.Encrypt(message, password);
var decryptedMessage = await CryptoProcessor.Decrypt(encryptedData, password);
Assert.That(decryptedMessage, Is.EqualTo(message));
}
@ -108,11 +108,11 @@ namespace Encrypter_Tests
var password1 = "password!";
var password2 = "password.";
var encryptedData = await CryptoProcessor.EncryptString(message, password1);
var encryptedData = await CryptoProcessor.Encrypt(message, password1);
try
{
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password2);
var decryptedMessage = await CryptoProcessor.Decrypt(encryptedData, password2);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -140,16 +140,16 @@ namespace Encrypter_Tests
var previousIterations = 1_000;
var upgradedIterations = 1_000_000;
var previousEncryptedData = await CryptoProcessor.EncryptString(message, password, previousIterations);
var previousEncryptedData = await CryptoProcessor.Encrypt(message, password, previousIterations);
var reEncryptedData = await CryptoProcessor.UpgradeIterations(previousEncryptedData, password, previousIterations, upgradedIterations);
Assert.That(previousEncryptedData, Is.Not.EqualTo(reEncryptedData));
var decryptedMessage = await CryptoProcessor.DecryptString(reEncryptedData, password, upgradedIterations);
var decryptedMessage = await CryptoProcessor.Decrypt(reEncryptedData, password, upgradedIterations);
Assert.That(decryptedMessage, Is.EqualTo(message));
try
{
var decryptedMessage2 = await CryptoProcessor.DecryptString(reEncryptedData, password, previousIterations);
var decryptedMessage2 = await CryptoProcessor.Decrypt(reEncryptedData, password, previousIterations);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -159,7 +159,7 @@ namespace Encrypter_Tests
try
{
var decryptedMessage2 = await CryptoProcessor.DecryptString(previousEncryptedData, password, upgradedIterations);
var decryptedMessage2 = await CryptoProcessor.Decrypt(previousEncryptedData, password, upgradedIterations);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -176,16 +176,16 @@ namespace Encrypter_Tests
var newPassword = "test password!!!";
var iterations = 1_000;
var previousEncryptedData = await CryptoProcessor.EncryptString(message, previousPassword, iterations);
var previousEncryptedData = await CryptoProcessor.Encrypt(message, previousPassword, iterations);
var reEncryptedData = await CryptoProcessor.ChangePassword(previousEncryptedData, previousPassword, newPassword, iterations);
Assert.That(previousEncryptedData, Is.Not.EqualTo(reEncryptedData));
var decryptedMessage = await CryptoProcessor.DecryptString(reEncryptedData, newPassword, iterations);
var decryptedMessage = await CryptoProcessor.Decrypt(reEncryptedData, newPassword, iterations);
Assert.That(decryptedMessage, Is.EqualTo(message));
try
{
var decryptedMessage2 = await CryptoProcessor.DecryptString(reEncryptedData, previousPassword, iterations);
var decryptedMessage2 = await CryptoProcessor.Decrypt(reEncryptedData, previousPassword, iterations);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -195,7 +195,7 @@ namespace Encrypter_Tests
try
{
var decryptedMessage2 = await CryptoProcessor.DecryptString(previousEncryptedData, newPassword, iterations);
var decryptedMessage2 = await CryptoProcessor.Decrypt(previousEncryptedData, newPassword, iterations);
Assert.Fail("Should not be reached!");
}
catch (CryptographicException e)
@ -216,8 +216,8 @@ namespace Encrypter_Tests
try
{
await File.WriteAllTextAsync(tempSourceFile, message);
await CryptoProcessor.EncryptStream(File.OpenRead(tempSourceFile), File.OpenWrite(tempDestFile), password);
await CryptoProcessor.DecryptStream(File.OpenRead(tempDestFile), File.OpenWrite(tempFinalFile), password);
await CryptoProcessor.Encrypt(File.OpenRead(tempSourceFile), File.OpenWrite(tempDestFile), password);
await CryptoProcessor.Decrypt(File.OpenRead(tempDestFile), File.OpenWrite(tempFinalFile), password);
Assert.That(File.Exists(tempDestFile), Is.True);
Assert.That(File.Exists(tempFinalFile), Is.True);
@ -277,8 +277,8 @@ namespace Encrypter_Tests
var fileInfoSource = new FileInfo(tempSourceFile);
Assert.That(fileInfoSource.Length, Is.EqualTo(32_000_000_000));
await CryptoProcessor.EncryptStream(File.OpenRead(tempSourceFile), File.OpenWrite(tempDestFile), password);
await CryptoProcessor.DecryptStream(File.OpenRead(tempDestFile), File.OpenWrite(tempFinalFile), password);
await CryptoProcessor.Encrypt(File.OpenRead(tempSourceFile), File.OpenWrite(tempDestFile), password);
await CryptoProcessor.Decrypt(File.OpenRead(tempDestFile), File.OpenWrite(tempFinalFile), password);
Assert.That(File.Exists(tempDestFile), Is.True);
Assert.That(File.Exists(tempFinalFile), Is.True);

View File

@ -25,7 +25,7 @@ namespace Encrypter
/// <param name="password">The password. Must consists of 6 chars or more.</param>
/// <param name="iterations">The number of iterations to derive the key. Should not be adjusted. The default is secure for the current time.</param>
/// <returns>The base64 encoded and encrypted string. The string is ASCII encoding.</returns>
public static async Task<string> EncryptString(string data, string password, int iterations = ITERATIONS_YEAR_2020)
public static async Task<string> Encrypt(string data, string password, int iterations = ITERATIONS_YEAR_2020)
{
if (string.IsNullOrWhiteSpace(password) || password.Length < 6)
throw new CryptographicException("The password was empty or shorter than 6 characters.");
@ -101,7 +101,7 @@ namespace Encrypter
/// <param name="outputStream">The desired output stream. The encrypted data gets written to the current position.</param>
/// <param name="password">The encryption password.</param>
/// <param name="iterations">The desired number of iterations to create the key. Should not be adjusted. The default is secure for the current time.</param>
public static async Task EncryptStream(Stream inputStream, Stream outputStream, string password, int iterations = ITERATIONS_YEAR_2020)
public static async Task Encrypt(Stream inputStream, Stream outputStream, string password, int iterations = ITERATIONS_YEAR_2020)
{
if (string.IsNullOrWhiteSpace(password) || password.Length < 6)
throw new CryptographicException("The password was empty or shorter than 6 characters.");
@ -171,7 +171,7 @@ namespace Encrypter
/// <param name="password">The password. Must consists of 6 chars or more.</param>
/// <param name="iterations">The number of iterations to derive the key. Should not be adjusted. The default is secure for the current time.</param>
/// <returns>The decrypted UTF8 encoded string.</returns>
public static async Task<string> DecryptString(string base64EncodedAndEncryptedData, string password, int iterations = ITERATIONS_YEAR_2020)
public static async Task<string> Decrypt(string base64EncodedAndEncryptedData, string password, int iterations = ITERATIONS_YEAR_2020)
{
if (string.IsNullOrWhiteSpace(password) || password.Length < 6)
throw new CryptographicException("The password was empty or shorter than 6 characters.");
@ -245,7 +245,7 @@ namespace Encrypter
/// <param name="outputStream">The desired output stream. The decrypted data gets written to the current position.</param>
/// <param name="password">The encryption password.</param>
/// <param name="iterations">The desired number of iterations to create the key. Should not be adjusted. The default is secure for the current time.</param>
public static async Task DecryptStream(Stream inputStream, Stream outputStream, string password, int iterations = ITERATIONS_YEAR_2020)
public static async Task Decrypt(Stream inputStream, Stream outputStream, string password, int iterations = ITERATIONS_YEAR_2020)
{
if (string.IsNullOrWhiteSpace(password) || password.Length < 6)
throw new CryptographicException("The password was empty or shorter than 6 characters.");
@ -313,10 +313,10 @@ namespace Encrypter
public static async Task<string> UpgradeIterations(string encryptedDataBeforeUpgrade, string password, int previousIterations, int upgradedIterations)
{
// Decrypt the data with the previous settings:
var decryptedData = await CryptoProcessor.DecryptString(encryptedDataBeforeUpgrade, password, previousIterations);
var decryptedData = await CryptoProcessor.Decrypt(encryptedDataBeforeUpgrade, password, previousIterations);
// Encrypt the data with the new settings:
return await CryptoProcessor.EncryptString(decryptedData, password, upgradedIterations);
return await CryptoProcessor.Encrypt(decryptedData, password, upgradedIterations);
}
/// <summary>
@ -330,10 +330,10 @@ namespace Encrypter
public static async Task<string> ChangePassword(string encryptedDataBeforeChange, string previousPassword, string newPassword, int iterations = ITERATIONS_YEAR_2020)
{
// Decrypt the data with the previous settings:
var decryptedData = await CryptoProcessor.DecryptString(encryptedDataBeforeChange, previousPassword, iterations);
var decryptedData = await CryptoProcessor.Decrypt(encryptedDataBeforeChange, previousPassword, iterations);
// Encrypt the data with the new settings:
return await CryptoProcessor.EncryptString(decryptedData, newPassword, iterations);
return await CryptoProcessor.Encrypt(decryptedData, newPassword, iterations);
}
}
}

View File

@ -9,7 +9,7 @@
The number of iterations for the year 2020.
</summary>
</member>
<member name="M:Encrypter.CryptoProcessor.EncryptString(System.String,System.String,System.Int32)">
<member name="M:Encrypter.CryptoProcessor.Encrypt(System.String,System.String,System.Int32)">
<summary>
Encrypts a string by means of AES. The result gets base64 encoded.
Due to the necessary millions of SHA512 iterations, the methods runs at least several seconds in the year 2020 (approx. 5-7s).
@ -22,7 +22,7 @@
<param name="iterations">The number of iterations to derive the key. Should not be adjusted. The default is secure for the current time.</param>
<returns>The base64 encoded and encrypted string. The string is ASCII encoding.</returns>
</member>
<member name="M:Encrypter.CryptoProcessor.EncryptStream(System.IO.Stream,System.IO.Stream,System.String,System.Int32)">
<member name="M:Encrypter.CryptoProcessor.Encrypt(System.IO.Stream,System.IO.Stream,System.String,System.Int32)">
<summary>
Encrypts a given input stream and writes the encrypted data to the provided output stream. A buffer stream
gets used in front of the output stream. This method expects, that both streams are read-to-use e.g. the
@ -37,7 +37,7 @@
<param name="password">The encryption password.</param>
<param name="iterations">The desired number of iterations to create the key. Should not be adjusted. The default is secure for the current time.</param>
</member>
<member name="M:Encrypter.CryptoProcessor.DecryptString(System.String,System.String,System.Int32)">
<member name="M:Encrypter.CryptoProcessor.Decrypt(System.String,System.String,System.Int32)">
<summary>
Decrypts an base64 encoded and encrypted string. Due to the necessary millions of SHA512 iterations,
the methods runs at least several seconds in the year 2020 (approx. 5-7s).
@ -50,7 +50,7 @@
<param name="iterations">The number of iterations to derive the key. Should not be adjusted. The default is secure for the current time.</param>
<returns>The decrypted UTF8 encoded string.</returns>
</member>
<member name="M:Encrypter.CryptoProcessor.DecryptStream(System.IO.Stream,System.IO.Stream,System.String,System.Int32)">
<member name="M:Encrypter.CryptoProcessor.Decrypt(System.IO.Stream,System.IO.Stream,System.String,System.Int32)">
<summary>
Decrypts a given input stream and writes the decrypted data to the provided output stream. A buffer stream
gets used in front of the output stream. This method expects, that both streams are read-to-use e.g. the

View File

@ -21,7 +21,7 @@ namespace Encrypter
/// <returns>The base64 encoded and encrypted string. The string is ASCII encoding.</returns>
public static async Task<string> Encrypt(this string data, string password, int iterations = CryptoProcessor.ITERATIONS_YEAR_2020)
{
return await CryptoProcessor.EncryptString(data, password, iterations);
return await CryptoProcessor.Encrypt(data, password, iterations);
}
/// <summary>
@ -39,7 +39,7 @@ namespace Encrypter
/// <param name="iterations">The number of iterations to derive the key. Should not be adjusted. The default is secure for the current time.</param>
public static async Task Encrypt(this Stream inputStream, Stream outputStream, string password, int iterations = CryptoProcessor.ITERATIONS_YEAR_2020)
{
await CryptoProcessor.EncryptStream(inputStream, outputStream, password, iterations);
await CryptoProcessor.Encrypt(inputStream, outputStream, password, iterations);
}
/// <summary>
@ -55,7 +55,7 @@ namespace Encrypter
/// <returns>The decrypted UTF8 encoded string.</returns>
public static async Task<string> Decrypt(this string data, string password, int iterations = CryptoProcessor.ITERATIONS_YEAR_2020)
{
return await CryptoProcessor.DecryptString(data, password, iterations);
return await CryptoProcessor.Decrypt(data, password, iterations);
}
/// <summary>
@ -73,7 +73,7 @@ namespace Encrypter
/// <param name="iterations">The number of iterations to derive the key. Should not be adjusted. The default is secure for the current time.</param>
public static async Task Decrypt(this Stream inputStream, Stream outputStream, string password, int iterations = CryptoProcessor.ITERATIONS_YEAR_2020)
{
await CryptoProcessor.DecryptStream(inputStream, outputStream, password, iterations);
await CryptoProcessor.Decrypt(inputStream, outputStream, password, iterations);
}
}
}