Exemplo n.º 1
0
 public static int[] DecryptVote(this Vote vote, PrivateKey key)
 {
     if (vote == null || key == null || vote.EncryptedVector == null)
     {
         throw new Exception("Can't decrypt vote. Null key or vote");
     }
     return(vote.EncryptedVector.Select(arg => HomoCrypto.Decrypt(arg, key)).ToArray());
 }
Exemplo n.º 2
0
        public bool TryDecryptElectionResultIfFinished(Election election)
        {
            if (!election.IsFinished)
            {
                return(false);
            }

            PrivateKey privateKey;

            if (!electionPrivateKeys.TryGetValue(election.Id, out privateKey))
            {
                return(false);
            }

            election.DecryptedResult = (election.EncryptedResult ?? Enumerable.Repeat(BigInteger.Zero, election.Candidates.Count)).Select(voteElement => HomoCrypto.Decrypt(voteElement, privateKey)).ToArray();

            return(true);
        }