Example #1
0
        public override unsafe bool TryCreateSignature(ReadOnlySpan <byte> hash, Span <byte> destination, out int bytesWritten)
        {
            Span <byte>         stackBuf = stackalloc byte[WindowsMaxQSize];
            ReadOnlySpan <byte> source   = AdjustHashSizeIfNecessary(hash, stackBuf);

            using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
            {
                return(CngCommon.TrySignHash(keyHandle, source, destination, AsymmetricPaddingMode.None, null, out bytesWritten));
            }
        }
Example #2
0
 public override unsafe bool TryCreateSignature(ReadOnlySpan <byte> hash, Span <byte> destination, out int bytesWritten)
 {
     byte[] arrayToReturnToArrayPool = AdjustHashSizeIfNecessaryWithArrayPool(ref hash);
     try
     {
         using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
         {
             return(CngCommon.TrySignHash(keyHandle, hash, destination, AsymmetricPaddingMode.None, null, out bytesWritten));
         }
     }
     finally
     {
         if (arrayToReturnToArrayPool != null)
         {
             Array.Clear(arrayToReturnToArrayPool, 0, hash.Length);
             ArrayPool <byte> .Shared.Return(arrayToReturnToArrayPool);
         }
     }
 }
Example #3
0
        public override unsafe bool TryCreateSignature(ReadOnlySpan <byte> hash, Span <byte> destination, out int bytesWritten)
#endif
        {
            Span <byte>         stackBuf = stackalloc byte[WindowsMaxQSize];
            ReadOnlySpan <byte> source   = AdjustHashSizeIfNecessary(hash, stackBuf);

            using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
            {
                if (!CngCommon.TrySignHash(keyHandle, source, destination, AsymmetricPaddingMode.None, null, out bytesWritten))
                {
                    bytesWritten = 0;
                    return(false);
                }
            }

#if INTERNAL_ASYMMETRIC_IMPLEMENTATIONS
            if (signatureFormat == DSASignatureFormat.IeeeP1363FixedFieldConcatenation)
            {
                return(true);
            }

            if (signatureFormat != DSASignatureFormat.Rfc3279DerSequence)
            {
                Debug.Fail($"Missing internal implementation handler for signature format {signatureFormat}");
                throw new CryptographicException(
                          SR.Cryptography_UnknownSignatureFormat,
                          signatureFormat.ToString());
            }

            return(AsymmetricAlgorithmHelpers.TryConvertIeee1363ToDer(
                       destination.Slice(0, bytesWritten),
                       destination,
                       out bytesWritten));
#else
            return(true);
#endif
        }