Example #1
0
        private static byte[] SignMessage(X509Certificate2 certificate, byte[] message)
        {
            // Создание объекта для подписи сообщения
            var signedCms = new GostSignedCms(new ContentInfo(message), true);

            // Создание объектс с информацией о подписчике
            var signer = new CmsSigner(certificate);

            // Включение информации только о конечном сертификате (только для теста)
            signer.IncludeOption = X509IncludeOption.EndCertOnly;

            // Создание подписи для сообщения CMS/PKCS#7
            signedCms.ComputeSignature(signer);

            // Создание подписи CMS/PKCS#7
            return(signedCms.Encode());
        }
Example #2
0
        /// <summary>
        /// Signs the message with a GOST digital signature and returns the attached signature (CMS format, base64 encoding).
        /// </summary>
        public static string ComputeAttachedSignature(X509Certificate2 certificate, byte[] message)
        {
            // The following line opens the private key.
            // It requires that the current user has permissions to use the private key.
            // Permissions are given using MMC console, Certificates snap-in.
            var privateKey = (GostAsymmetricAlgorithm)certificate.GetPrivateKeyAlgorithm();
            var publicKey  = (GostAsymmetricAlgorithm)certificate.GetPublicKeyAlgorithm();

            // Create GOST-compliant signature helper
            var signedCms = new GostSignedCms(new ContentInfo(message), detached: false);

            // The object that has the signer information
            var signer = new CmsSigner(certificate);

            // Computing the CMS/PKCS#7 signature
            signedCms.ComputeSignature(signer, true);

            // Encoding the CMS/PKCS#7 message
            var encoded = signedCms.Encode();

            return(Convert.ToBase64String(encoded));
        }