コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public string GetMyVote(EncryptedKeyPair crypticKeyPair)
 {
     this.blockchain.TryGetVoteByVoter(Convert.ToBase64String(crypticKeyPair.PublicKey), out Vote vote);
     return(vote.Ballot);
 }