Esempio n. 1
0
        public bool VerifyEmbedded(AsymmetricAlgorithm key, byte[]?associatedData = null)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (Message.IsDetached)
            {
                throw new InvalidOperationException(SR.ContentWasDetached);
            }

            return(VerifyCore(key, Message.Content.Value.Span, null, associatedData, CoseHelpers.GetKeyType(key)));
        }
Esempio n. 2
0
        public bool VerifyDetached(AsymmetricAlgorithm key, ReadOnlySpan <byte> detachedContent, ReadOnlySpan <byte> associatedData = default)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (!Message.IsDetached)
            {
                throw new InvalidOperationException(SR.ContentWasEmbedded);
            }

            return(VerifyCore(key, detachedContent, null, associatedData, CoseHelpers.GetKeyType(key)));
        }
Esempio n. 3
0
        public CoseSigner(AsymmetricAlgorithm key, HashAlgorithmName hashAlgorithm, CoseHeaderMap?protectedHeaders = null, CoseHeaderMap?unprotectedHeaders = null)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (key is RSA)
            {
                throw new CryptographicException(SR.CoseSignerRSAKeyNeedsPadding);
            }

            Key           = key;
            HashAlgorithm = hashAlgorithm;

            _protectedHeaders     = protectedHeaders;
            _unprotectedHeaders   = unprotectedHeaders;
            _keyType              = CoseHelpers.GetKeyType(key);
            _algHeaderValueToSlip = ValidateOrSlipAlgorithmHeader();
        }
Esempio n. 4
0
        public CoseSigner(RSA key, RSASignaturePadding signaturePadding, HashAlgorithmName hashAlgorithm, CoseHeaderMap?protectedHeaders = null, CoseHeaderMap?unprotectedHeaders = null)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (signaturePadding is null)
            {
                throw new ArgumentNullException(nameof(signaturePadding));
            }

            Key                 = key;
            HashAlgorithm       = hashAlgorithm;
            RSASignaturePadding = signaturePadding;

            _protectedHeaders     = protectedHeaders;
            _unprotectedHeaders   = unprotectedHeaders;
            _keyType              = CoseHelpers.GetKeyType(key);
            _algHeaderValueToSlip = ValidateOrSlipAlgorithmHeader();
        }