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

                var containerKey = keyContainer.ExportPublicKey();

                Assert.AreEqual(containerKey, publicKeyFromCert);
            }
        }
        /// <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 (KeyContainer keyContainer = KeyContainer.Open(Container, ContainerPassword))
            {
                byte[] signature = keyContainer.SignHash(hashValue, KeyNumber.Signature);
                return(Convert.ToBase64String(signature));
            }
        }
Example #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);
        }
Example #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);
        }