コード例 #1
0
 public void ComputeHashFromBytes()
 {
     var expected = Utilities.HexToBinary("8866267f985204ae511980704ac85ec4936ee535c37541f342976b2cb3ac62fd");
       var hashStream = new GenericHash.GenericHashAlgorithm("This is a test key", 32);
       var actual = hashStream.ComputeHash(Encoding.UTF8.GetBytes("Adam Caudill"));
       CollectionAssert.AreEqual(expected, actual);
 }
コード例 #2
0
 public void ComputeHashFromNullStream()
 {
     var expected = Utilities.HexToBinary("4afd15412c1b940d7cffc9049b9ed413cbaeb626aca2a70c2afbeea7a85bdf8e");
       var stream = Stream.Null;
       var hashStream = new GenericHash.GenericHashAlgorithm("This is a test key", 32);
       var actual = hashStream.ComputeHash(stream);
       CollectionAssert.AreEqual(expected, actual);
 }
コード例 #3
0
ファイル: Hashing.cs プロジェクト: modulexcite/PoSH-Sodium
        protected override void ProcessRecord()
        {
            byte[] hashedMessage;
            var key = Key.HasValue() ? Key.ToByteArrayFromBase64String() : null;

            if (ParameterSetName == "File")
            {
                using (ICryptoTransform transform = new GenericHash.GenericHashAlgorithm(key, HashLength))
                using (MemoryStream destination = new MemoryStream())
                using (CryptoStream cryptoStream = new CryptoStream(destination, transform, CryptoStreamMode.Write))
                using (FileStream source = new FileStream(File, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    source.CopyTo(cryptoStream);
                    cryptoStream.FlushFinalBlock();
                    hashedMessage = destination.ToArray();
                }
            }
            else
            {
                hashedMessage = GenericHash.Hash(rawMessage, key, HashLength);
            }

            if (Raw.IsTrue())
            {
                WriteObject(hashedMessage);
            }
            else
            {
                WriteObject(hashedMessage.ToBase64String());
            }
        }