コード例 #1
0
        public void HashTestFromWiki()
        {
            //GOST("") = 981E5F3CA30C841487830F84FB433E13AC1101569B9C13584AC483234CD656C0
            byte[] data = Encoding.UTF8.GetBytes("");
            byte[] hash = Gost2001KeyContainer.ComputeHash(data);

            var hexString = HexEncoding.ToString(hash);

            Assert.AreEqual("981E5F3CA30C841487830F84FB433E13AC1101569B9C13584AC483234CD656C0", hexString);


            //GOST("a") = E74C52DD282183BF37AF0079C9F78055715A103F17E3133CEFF1AACF2F403011
            data = Encoding.UTF8.GetBytes("a");
            hash = Gost2001KeyContainer.ComputeHash(data);

            hexString = HexEncoding.ToString(hash);
            Assert.AreEqual("E74C52DD282183BF37AF0079C9F78055715A103F17E3133CEFF1AACF2F403011", hexString);


            //GOST("abc") = B285056DBF18D7392D7677369524DD14747459ED8143997E163B2986F92FD42C
            data = Encoding.UTF8.GetBytes("abc");
            hash = Gost2001KeyContainer.ComputeHash(data);

            hexString = HexEncoding.ToString(hash);
            Assert.AreEqual("B285056DBF18D7392D7677369524DD14747459ED8143997E163B2986F92FD42C", hexString);


            //GOST("message digest") = BC6041DD2AA401EBFA6E9886734174FEBDB4729AA972D60F549AC39B29721BA0
            data = Encoding.UTF8.GetBytes("message digest");
            hash = Gost2001KeyContainer.ComputeHash(data);

            hexString = HexEncoding.ToString(hash);
            Assert.AreEqual("BC6041DD2AA401EBFA6E9886734174FEBDB4729AA972D60F549AC39B29721BA0", hexString);
        }
コード例 #2
0
        public void ComputeHash()
        {
            byte[] data = GetRandomData();

            byte[] hash = Gost2001KeyContainer.ComputeHash(data);

            const int HashLength = 32;

            Assert.AreEqual(HashLength, hash.Length);
        }
コード例 #3
0
 /// <summary>
 ///     Подсчет хэша.
 /// </summary>
 /// <param name="data">Данные.</param>
 /// <returns>Хэш.</returns>
 public string ComputeHash(string data)
 {
     log.Debug("ComputeHash: data: {0}", data);
     if (data == null)
     {
         throw new WebFaultException(HttpStatusCode.BadRequest);
     }
     byte[] dataValue = Encoding.UTF8.GetBytes(data);
     return(Convert.ToBase64String(Gost2001KeyContainer.ComputeHash(dataValue)));
 }
コード例 #4
0
        public void SignHash()
        {
            byte[] data = GetRandomData();

            byte[] signature;
            byte[] hash = Gost2001KeyContainer.ComputeHash(data);

            using (GostCryptFacade keyContainer = Gost2001KeyContainer.Open(Container, ContainerPassword))
            {
                signature = keyContainer.SignHash(hash, KeyNumber.Signature);
            }

            byte[] publicKey = Gost2001KeyContainer.ExportPublicKey(Container);
            bool   result    = Gost2001KeyContainer.VerifySignature(signature, data, publicKey);

            Assert.IsTrue(result);
        }
コード例 #5
0
        public void SignCertigicateSignature()
        {
            byte[] data = GetRandomData();

            byte[] signature, certificateRawData;
            byte[] hash = Gost2001KeyContainer.ComputeHash(data);


            using (GostCryptFacade keyContainer = Gost2001KeyContainer.Open(ContainerSert, ContainerPassword))
            {
                signature          = keyContainer.SignHash(hash, KeyNumber.Signature);
                certificateRawData = keyContainer.ExportCertificateData();
            }

            bool result = Gost2001KeyContainer.VerifyCertificate(signature, data, certificateRawData);

            Assert.IsTrue(result);
        }