-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add ProtectedData based encryption utility - Add PackageReference to FluentFTP library (MIT License) - Add FTP credentials collection form - Add logic to Form1.cs to conditionally display FTP credentials popup
- Loading branch information
Showing
9 changed files
with
519 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace ARKBreedingStats.miscClasses | ||
{ | ||
class Encryption | ||
{ | ||
private static byte[] additionalEntropy = Encoding.UTF8.GetBytes("Additional Entropy"); | ||
|
||
/// <summary> | ||
/// Converts a string into a base64 encoded ProdectedData encrypted byte array | ||
/// </summary> | ||
/// <param name="value">The string to encrypt</param> | ||
public static string Protect(string value) | ||
{ | ||
try | ||
{ | ||
var decryptedBytes = Encoding.UTF8.GetBytes(value); | ||
|
||
// Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted | ||
// only by the same current user. | ||
var encryptedBytes = ProtectedData.Protect(decryptedBytes, additionalEntropy, DataProtectionScope.CurrentUser); | ||
|
||
return Convert.ToBase64String(encryptedBytes); | ||
} | ||
catch (CryptographicException e) | ||
{ | ||
Console.WriteLine("Data was not encrypted. An error occurred."); | ||
Console.WriteLine(e.ToString()); | ||
return null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Converts base64 encoded ProdectedData encrypted byte array into a string | ||
/// </summary> | ||
/// <param name="value">The string to decrypt</param> | ||
public static string Unprotect(string value) | ||
{ | ||
if (value == null) | ||
{ | ||
return null; | ||
} | ||
|
||
try | ||
{ | ||
var encryptedBytes = Convert.FromBase64String(value); | ||
|
||
//Decrypt the data using DataProtectionScope.CurrentUser. | ||
var decryptedBytes = ProtectedData.Unprotect(encryptedBytes, additionalEntropy, DataProtectionScope.CurrentUser); | ||
|
||
return Encoding.UTF8.GetString(decryptedBytes); | ||
} | ||
catch (CryptographicException e) | ||
{ | ||
Console.WriteLine("Data was not decrypted. An error occurred."); | ||
Console.WriteLine(e.ToString()); | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ARKBreedingStats.miscClasses | ||
{ | ||
public class FtpCredentials | ||
{ | ||
public string Username { get; set; } | ||
|
||
public string Password { get; set; } | ||
} | ||
} |
Oops, something went wrong.