public void ExportPublicKey() { using (GostCryptFacade keyContainer = Gost2001KeyContainer.Open(Container, ContainerPassword)) { byte[] key = keyContainer.ExportPublicKey(); CollectionAssert.IsNotEmpty(key); } }
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); } }
/// <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)); } }
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); }
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); }