예제 #1
0
        public override byte[] CreateSignature(byte[] rgbHash)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException(nameof(rgbHash));
            }

            ReadOnlySpan <byte> source = rgbHash;

            byte[] arrayToReturnToArrayPool = AdjustHashSizeIfNecessaryWithArrayPool(ref source);
            try
            {
                using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
                {
                    unsafe
                    {
                        return(CngCommon.SignHash(keyHandle, source, AsymmetricPaddingMode.None, null, source.Length * 2));
                    }
                }
            }
            finally
            {
                if (arrayToReturnToArrayPool != null)
                {
                    Array.Clear(arrayToReturnToArrayPool, 0, source.Length);
                    ArrayPool <byte> .Shared.Return(arrayToReturnToArrayPool);
                }
            }
        }
예제 #2
0
        public override byte[] CreateSignature(byte[] rgbHash)
        {
            ArgumentNullException.ThrowIfNull(rgbHash);

            Span <byte>         stackBuf = stackalloc byte[WindowsMaxQSize];
            ReadOnlySpan <byte> source   = AdjustHashSizeIfNecessary(rgbHash, stackBuf);

            using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
            {
                unsafe
                {
                    return(CngCommon.SignHash(keyHandle, source, AsymmetricPaddingMode.None, null, source.Length * 2));
                }
            }
        }
예제 #3
0
        public override byte[] CreateSignature(byte[] hash)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }

            hash = AdjustHashSizeIfNecessary(hash);
            using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
            {
                unsafe
                {
                    byte[] signature = CngCommon.SignHash(keyHandle, hash, AsymmetricPaddingMode.None, null, hash.Length * 2);
                    return(signature);
                }
            }
        }