Пример #1
0
        public override byte[] CreateSignature(byte[] hash)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }

            SafeDsaHandle key = _key.Value;

            byte[] signature = new byte[Interop.Crypto.DsaEncodedSignatureSize(key)];

            int  signatureSize;
            bool success = Interop.Crypto.DsaSign(key, hash, hash.Length, signature, out signatureSize);

            if (!success)
            {
                throw Interop.Crypto.CreateOpenSslCryptographicException();
            }

            Debug.Assert(
                signatureSize <= signature.Length,
                "DSA_sign reported an unexpected signature size",
                "DSA_sign reported signatureSize was {0}, when <= {1} was expected",
                signatureSize,
                signature.Length);

            int signatureFieldSize = Interop.Crypto.DsaSignatureFieldSize(key) * BitsPerByte;

            byte[] converted = OpenSslAsymmetricAlgorithmCore.ConvertDerToIeee1363(signature, 0, signatureSize, signatureFieldSize);
            return(converted);
        }
        public override byte[] SignHash(byte[] hash)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }

            SafeEcKeyHandle key             = _key.Value;
            int             signatureLength = Interop.Crypto.EcDsaSize(key);

            byte[] signature = new byte[signatureLength];
            if (!Interop.Crypto.EcDsaSign(hash, hash.Length, signature, ref signatureLength, key))
            {
                throw Interop.Crypto.CreateOpenSslCryptographicException();
            }

            byte[] converted = OpenSslAsymmetricAlgorithmCore.ConvertDerToIeee1363(signature, 0, signatureLength, KeySize);

            return(converted);
        }