Beispiel #1
0
 public void ExportPublicKey()
 {
     using (GostCryptFacade keyContainer = Gost2001KeyContainer.Open(Container, ContainerPassword))
     {
         byte[] key = keyContainer.ExportPublicKey();
         CollectionAssert.IsNotEmpty(key);
     }
 }
Beispiel #2
0
        public void GetCertificatePublicKey()
        {
            using (GostCryptFacade keyContainer = Gost2001KeyContainer.Open(ContainerSert, ContainerPassword))
            {
                var certificateRawData = keyContainer.ExportCertificateData();
                var publicKeyFromCert  = Gost2001KeyContainer.GetCertificatePublicKey(certificateRawData);

                var containerKey = keyContainer.ExportPublicKey();

                Assert.AreEqual(containerKey, publicKeyFromCert);
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Подпись хэша.
        /// </summary>
        /// <param name="hash">Хэш.</param>
        /// <returns>Подпись хэша.</returns>
        public string SignHash(string hash)
        {
            if (string.IsNullOrWhiteSpace(hash))
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }

            log.Debug("SignHash: hash: {0}, keyNumber: {1}", hash, KeyNumber.Signature);
            byte[] hashValue = Convert.FromBase64String(hash);
            using (GostCryptFacade keyContainer = Gost2001KeyContainer.Open(Container, ContainerPassword))
            {
                byte[] signature = keyContainer.SignHash(hashValue, KeyNumber.Signature);
                return(Convert.ToBase64String(signature));
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }