-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dropbox/jack/4.2
Jack 4 5
- Loading branch information
Showing
32 changed files
with
545 additions
and
247 deletions.
There are no files selected for viewing
Binary file not shown.
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
42 changes: 42 additions & 0 deletions
42
Source/DfBAdminToolkit.Common/Extensions/StringExtension.cs
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,42 @@ | ||
using System; | ||
using System.Text; | ||
using System.Security.Cryptography; | ||
|
||
namespace DfBAdminToolkit.Common.Extensions | ||
{ | ||
public static class StringExtension | ||
{ | ||
public static string Encrypt( | ||
this string clearText, | ||
string optionalEntropy = null, | ||
DataProtectionScope scope = DataProtectionScope.LocalMachine) | ||
{ | ||
if (clearText == null) | ||
throw new ArgumentNullException("Clear text is null"); | ||
byte[] clearBytes = Encoding.UTF8.GetBytes(clearText); | ||
byte[] entropyBytes = string.IsNullOrEmpty(optionalEntropy) | ||
? null | ||
: Encoding.UTF8.GetBytes(optionalEntropy); | ||
byte[] encryptedBytes = ProtectedData.Protect(clearBytes, entropyBytes, scope); | ||
string encryptedString = "encrypted-" + Convert.ToBase64String(encryptedBytes); | ||
return encryptedString; | ||
} | ||
|
||
public static string Decrypt( | ||
this string encryptedText, | ||
string optionalEntropy = null, | ||
DataProtectionScope scope = DataProtectionScope.LocalMachine) | ||
{ | ||
if (encryptedText == null) | ||
throw new ArgumentNullException("Encrypted text is null"); | ||
//remove encrypted- tag from beginning | ||
encryptedText = encryptedText.Remove(0, 10); | ||
byte[] encryptedBytes = Convert.FromBase64String(encryptedText); | ||
byte[] entropyBytes = string.IsNullOrEmpty(optionalEntropy) | ||
? null | ||
: Encoding.UTF8.GetBytes(optionalEntropy); | ||
byte[] clearBytes = ProtectedData.Unprotect(encryptedBytes, entropyBytes, scope); | ||
return Encoding.UTF8.GetString(clearBytes); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.