Пример #1
0
        public static byte[] SignRsa(RSACryptoServiceProvider rsaCsp, byte[] hash)
        {
            if (rsaCsp == null)
            {
                throw new ArgumentNullException(nameof(rsaCsp));
            }

            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }

            var cspInfo  = rsaCsp.CspKeyContainerInfo;
            var provider = new CngProvider(cspInfo.ProviderName);
            var options  = CngKeyOpenOptions.None;

            if (cspInfo.MachineKeyStore)
            {
                options = CngKeyOpenOptions.MachineKey;
            }

            using (var cngKey = CngKey.Open(cspInfo.KeyContainerName, provider, options))
            {
                var result = NCryptInterop.SignHashRaw(cngKey, hash, rsaCsp.KeySize);
                return(result);
            }
        }
Пример #2
0
        public static byte[] SignRsa(CngKey cngKey, byte[] hash)
        {
            if (cngKey == null)
            {
                throw new ArgumentNullException(nameof(cngKey));
            }

            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }

            var result = NCryptInterop.SignHashRaw(cngKey, hash, cngKey.KeySize);

            return(result);
        }