/// <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)); } }
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); }
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); }