public void GetPlaintextMasterKeyReturnsSameKeyForSamePassword() { var u = new DBUser(); u.Username = "******"; var password = "******"; u.CreateCryptoFields(password); var key1 = u.GetPlaintextMasterKey(password); var key2 = u.GetPlaintextMasterKey(password); Assert.AreEqual(key1, key2); Assert.AreEqual(key1.ToHexString(), key2.ToHexString()); }
public static void AddDummyUserIfRequired(Funq.Container container) { // create a dummy user var fac = container.Resolve <IDbConnectionFactory> (); using (var db = fac.OpenDbConnection()) { if (db.FirstOrDefault <DBUser> (u => u.Username == "dummy") == null) { var user = new DBUser(); user.Username = "******"; user.CreateCryptoFields("foobar123"); user.FirstName = "John Dummy"; user.LastName = "Doe"; user.AdditionalData = "Dummy user that is created when in development mode"; user.IsActivated = true; user.IsVerified = true; user.Manifest.LastSyncRevision = 0; user.EmailAddress = "*****@*****.**"; db.Insert <DBUser> (user); // insert some sample notes var f = container.Resolve <DbStorageFactory> (); var key = user.GetPlaintextMasterKey("foobar123"); var r = new RequestingUser { Username = "******", EncryptionMasterKey = key.ToHexString() }; // populate with note test cases taken from Tomdroid // these notes will fail Tomboy... using (var storage = f.GetDbStorage(r)) { var sample_notes = new DiskStorage("../../../sample_notes/"); sample_notes.GetNotes().Values.ToList().ForEach(n => storage.SaveNote(n)); } } } }
private AccessToken GenerateAccessToken(string username, string password, DateTime?expiry = null) { if (!expiry.HasValue) { expiry = DateTime.Now.AddYears(99); } var rng = new RNGCryptoServiceProvider(); string access_token_secret = rng.Create256BitLowerCaseHexKey(); string token_key = rng.Create256BitLowerCaseHexKey(); // the token is the master key encrypted with the token key string access_token_token; using (var db = connFactory.OpenDbConnection()) { DBUser user = db.First <DBUser> (u => u.Username == username); string master_key = user.GetPlaintextMasterKey(password).ToHexString(); access_token_token = master_key.EncryptWithKey(token_key, user.MasterKeySalt); } var access_token = new AccessToken() { ConsumerKey = "anyone", Realm = "Rainy", Token = access_token_token, TokenSecret = access_token_secret, UserName = username, ExpiryDate = expiry.Value }; access_token.SetTokenKey(token_key); return(access_token); }
public void GetPlaintextMasterKeyReturns256Bit() { var u = new DBUser(); u.Username = "******"; var password = "******"; u.CreateCryptoFields(password); var master_key = u.GetPlaintextMasterKey(password); Assert.AreEqual(32, master_key.Length); }
public void BasicEncryptAndDecrypt() { var u = new DBUser(); u.Username = "******"; var password = "******"; u.CreateCryptoFields(password); var test_string = "The quick brown fox jumps over the lazy dog."; var master_key = u.GetPlaintextMasterKey(password); byte[] encrypted_bytes = u.EncryptString(master_key, test_string); string decrypted_string = u.DecryptUnicodeString(master_key, encrypted_bytes); Assert.AreEqual(test_string, decrypted_string); }
public void EncryptDecryptWithHexRepresentation() { var u = new DBUser(); u.Username = "******"; var password = "******"; u.CreateCryptoFields(password); var master_key = u.GetPlaintextMasterKey(password); var key = master_key.ToHexString(); var test_string = "The quick brown fox jumps over the lazy dog."; byte[] encrypted_bytes = u.EncryptString(master_key, test_string); string encrypted_string = encrypted_bytes.ToHexString(); string decrypted_string = u.DecryptUnicodeString(master_key, encrypted_string.ToByteArray()); Assert.AreEqual(test_string, decrypted_string); }