-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed the password hint (for security reasons), added the functiona…
…lity to create an account/vault and login, validation not yet included, but AES is implemented and BCrypt is replaced with PBKDF2 instead.
- Loading branch information
Showing
14 changed files
with
364 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace vIDsafe | ||
{ | ||
[Serializable] | ||
class Credential | ||
{ | ||
public Credential() | ||
{ | ||
|
||
} | ||
} | ||
} |
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,93 @@ | ||
using SimpleCrypto; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Security.Cryptography; | ||
|
||
namespace vIDsafe | ||
{ | ||
class Encryption | ||
{ | ||
|
||
public static ICryptoService cryptoService = new PBKDF2(); | ||
private const int HASH_ITERATIONS = 100000; //Work factor, higher = longer | ||
|
||
private static string IV = "fu1$c!j2d8limk6x"; | ||
|
||
private const int HASH_SIZE = 32; | ||
|
||
//https://shawnmclean.com/simplecrypto-net-a-pbkdf2-hashing-wrapper-for-net-framework/ | ||
public static byte[] hashPassword(string newPassword, string salt) | ||
{ | ||
//a new password hash is generated from a generated salt with the passed settings | ||
//return cryptoService.Compute(newPassword, HASH_ITERATIONS + "." + salt); | ||
|
||
byte[] convertedSalt = ASCIIEncoding.ASCII.GetBytes(salt); | ||
|
||
// Generate the hash | ||
Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(newPassword, convertedSalt, HASH_ITERATIONS); | ||
return pbkdf2.GetBytes(HASH_SIZE); | ||
} | ||
|
||
//https://shawnmclean.com/simplecrypto-net-a-pbkdf2-hashing-wrapper-for-net-framework/ | ||
public static bool validatePassword(string password, string hashedPassword, string salt) | ||
{ | ||
//hash the password with the saved salt for that user | ||
string hashed = cryptoService.Compute(password, salt); | ||
//return true if both hashes are the same | ||
return hashed == hashedPassword; | ||
} | ||
|
||
public static string aesEncrypt(string plainText, byte[] key) | ||
{ | ||
byte[] textBytes = ASCIIEncoding.ASCII.GetBytes(plainText); | ||
|
||
AesCryptoServiceProvider AES = new AesCryptoServiceProvider | ||
{ | ||
BlockSize = 128, | ||
KeySize = 256, | ||
Key = key, | ||
IV = ASCIIEncoding.ASCII.GetBytes(IV), | ||
Padding = PaddingMode.PKCS7, | ||
Mode = CipherMode.CBC | ||
}; | ||
|
||
ICryptoTransform Encryptor = AES.CreateEncryptor(AES.Key, AES.IV); | ||
|
||
byte[] encryptedText = Encryptor.TransformFinalBlock(textBytes, 0, textBytes.Length); | ||
Encryptor.Dispose(); | ||
|
||
return Convert.ToBase64String(encryptedText); | ||
} | ||
|
||
|
||
public static string aesDecrypt(string encryptedText, byte[] key) | ||
{ | ||
byte[] textBytes = Convert.FromBase64String(encryptedText); | ||
AesCryptoServiceProvider AES = new AesCryptoServiceProvider | ||
{ | ||
BlockSize = 128, | ||
KeySize = 256, | ||
Key = key, | ||
IV = ASCIIEncoding.ASCII.GetBytes(IV), | ||
Padding = PaddingMode.PKCS7, | ||
Mode = CipherMode.CBC | ||
}; | ||
|
||
ICryptoTransform Encryptor = AES.CreateDecryptor(AES.Key, AES.IV); | ||
try | ||
{ | ||
byte[] decryptedText = Encryptor.TransformFinalBlock(textBytes, 0, textBytes.Length); | ||
Encryptor.Dispose(); | ||
|
||
return ASCIIEncoding.ASCII.GetString(decryptedText); | ||
} | ||
catch (CryptographicException) | ||
{ | ||
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
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,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace vIDsafe | ||
{ | ||
[Serializable] | ||
class Identity | ||
{ | ||
private List<Credential> credentials = new List<Credential>(); | ||
|
||
public Identity() | ||
{ | ||
|
||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.