Exemple #1
0
        public void HashTestFromWiki()
        {
            //GOST("") = 981E5F3CA30C841487830F84FB433E13AC1101569B9C13584AC483234CD656C0
            byte[] data = Encoding.UTF8.GetBytes("");
            byte[] hash = KeyContainer.ComputeHash(data);

            var hexString = HexEncoding.ToString(hash);

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


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

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


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

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


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

            hexString = HexEncoding.ToString(hash);
            Assert.AreEqual("BC6041DD2AA401EBFA6E9886734174FEBDB4729AA972D60F549AC39B29721BA0", hexString);
        }
 /// <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(KeyContainer.ComputeHash(dataValue)));
 }
Exemple #3
0
        public void ComputeHash()
        {
            byte[] data = GetRandomData();

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

            const int HashLength = 32;

            Assert.AreEqual(HashLength, hash.Length);
        }
Exemple #4
0
        public void SignHash()
        {
            byte[] data = GetRandomData();

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

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

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

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

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


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

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

            Assert.IsTrue(result);
        }