Example #1
0
        public string Encrypt(string input)
        {
            // var dgk = new DGK(_publicKey, _privateKey, new DecryptionParameters());
            //var dgk = new DGK(new SecurityParameters { k = 54, t = 9, l = 8}, new DecryptionParameters{dms = 4});
            // var dgk = new DGK(new SecurityParameters { k = 256, t = 9, l = 8}, new DecryptionParameters{dms = 4});
            var dgk = new DGK(new SecurityParameters {
                k = 1024, t = 160, l = 16
            },
                              new DecryptionParameters {
                dms = 4
            });

            var requirementBits = input.PadLeft(BitLength, '0').Select(bit => int.Parse((string)bit.ToString())).ToArray();

            var encryptedRequirementBits = requirementBits.Select(bit => dgk.Encrypt(bit)).ToArray();

            using var stream = new MemoryStream();

            foreach (var encryptedRequirementBit in encryptedRequirementBits)
            {
                stream.Write(encryptedRequirementBit.data.ToByteArray());
            }

            stream.Flush();
            stream.Position = 0;

            var hash = SHA3.CreateKeccak512().ComputeHash(stream);
            var hex  = Application.BitConverter.ByteArrayToHexViaLookup32(hash);

            return(hex);
        }
Example #2
0
        public void Sha3Of512BitsShouldProduceAValidHashResultForTheGivenMessage(string expected, string message)
        {
            // Arrange
            string actual;
            SHA3   algorithm = SHA3.CreateKeccak512();

            // Act
            actual = ComputeHash(algorithm, message);

            // Assert
            Assert.Equal(expected, actual);
        }
Example #3
0
        public void Sha3Of512BitsShouldProduceAValidHashResultForTheGivenSequence(string expected, string sequenceString, int sequenceLength)
        {
            // Arrange
            string actual;
            SHA3   algorithm = SHA3.CreateKeccak512();

            // Act
            actual = ComputeHash(algorithm, string.Concat(Enumerable.Repeat(sequenceString, sequenceLength)));

            // Assert
            Assert.Equal(expected, actual);
        }
Example #4
0
 public String GetSHA3_Keccak512(Param p)
 {
     byte[] h;
     if (p.Fs != null)
     {
         h = SHA3.CreateKeccak512().ComputeHash(p.Fs);
     }
     else
     {
         h = SHA3.CreateKeccak512().ComputeHash(Settings.GetEncoding().GetBytes(p.ValueToHash));
     }
     return(BitConverter.ToString(h));
 }