public bool TryGetVoterEncryptedKeyPair(string password, out EncryptedKeyPair encryptedKeyPair) { var passwordHash = PasswordHasher.Hash(password); var connection = this.OpenConnection(); var queryString = $"select * from voters where pw_hash = \"{passwordHash.GetBase64String()}\""; var query = new SQLiteCommand(queryString, connection); var reader = query.ExecuteReader(); if (!reader.Read()) { encryptedKeyPair = null; return(false); } var voterIdString = (string)reader["voter_id"]; var encryptedPrivateKeyString = (string)reader["encrypted_private_key"]; var ivString = (string)reader["iv"]; var hashedPasswordString = (string)reader["pw_hash"]; encryptedKeyPair = new EncryptedKeyPair( Convert.FromBase64String(voterIdString), null, Convert.FromBase64String(encryptedPrivateKeyString), Convert.FromBase64String(ivString), Convert.FromBase64String(hashedPasswordString)); return(true); }
public bool login(string password, out EncryptedKeyPair crypticKeyPair) { Console.WriteLine("Please enter your Voter Regestration Identification Number:\n"); string userSuppliedPassword = Console.ReadLine(); crypticKeyPair = null; var success = this.voterDb.TryGetVoterEncryptedKeyPair(userSuppliedPassword, out var encryptedKeyPair); if (!success) { return(false); } this.keyPair = encryptedKeyPair; this.password = userSuppliedPassword; return(true); }
public string GetMyVote(EncryptedKeyPair crypticKeyPair) { this.blockchain.TryGetVoteByVoter(Convert.ToBase64String(crypticKeyPair.PublicKey), out Vote vote); return(vote.Ballot); }