• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Tokens.SecurityKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.IdentityModel.Tokens.SecurityKey的典型用法代码示例。如果您正苦于以下问题:C# SecurityKey类的具体用法?C# SecurityKey怎么用?C# SecurityKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SecurityKey类属于System.IdentityModel.Tokens命名空间,在下文中一共展示了SecurityKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ComputeSignature

 public void ComputeSignature(SecurityKey signingKey)
 {
     string signatureMethod = this.Signature.SignedInfo.SignatureMethod;
     SymmetricSecurityKey key = signingKey as SymmetricSecurityKey;
     if (key != null)
     {
         using (KeyedHashAlgorithm algorithm = key.GetKeyedHashAlgorithm(signatureMethod))
         {
             if (algorithm == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("UnableToCreateKeyedHashAlgorithm", new object[] { key, signatureMethod })));
             }
             this.ComputeSignature(algorithm);
             return;
         }
     }
     AsymmetricSecurityKey key2 = signingKey as AsymmetricSecurityKey;
     if (key2 == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("UnknownICryptoType", new object[] { signingKey })));
     }
     using (HashAlgorithm algorithm2 = key2.GetHashAlgorithmForSignature(signatureMethod))
     {
         if (algorithm2 == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("UnableToCreateHashAlgorithmFromAsymmetricCrypto", new object[] { signatureMethod, key2 })));
         }
         AsymmetricSignatureFormatter signatureFormatter = key2.GetSignatureFormatter(signatureMethod);
         if (signatureFormatter == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("UnableToCreateSignatureFormatterFromAsymmetricCrypto", new object[] { signatureMethod, key2 })));
         }
         this.ComputeSignature(algorithm2, signatureFormatter, signatureMethod);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:SignedXml.cs


示例2: TryResolveSecurityKeyCore

        /// <summary>
        /// Inherited from <see cref="SecurityTokenResolver"/>.
        /// </summary>
        protected override bool TryResolveSecurityKeyCore( SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key )
        {
            if ( keyIdentifierClause == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "keyIdentifierClause" );
            }

            key = null;

            X509RawDataKeyIdentifierClause rawDataClause = keyIdentifierClause as X509RawDataKeyIdentifierClause;
            if ( rawDataClause != null )
            {
                key = rawDataClause.CreateKey();
                return true;
            }

            RsaKeyIdentifierClause rsaClause = keyIdentifierClause as RsaKeyIdentifierClause;
            if ( rsaClause != null )
            {
                key = rsaClause.CreateKey();
                return true;
            }

            if ( _wrappedTokenResolver.TryResolveSecurityKey( keyIdentifierClause, out key ) )
            {
                return true;
            }

            return false;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:33,代码来源:IssuerTokenResolver.cs


示例3: InitCrypto

 private void InitCrypto(SecurityKey securityKey)
 {
     m_securityKey = securityKey;
     List<SecurityKey> securityKeys = new List<SecurityKey>(1);
     securityKeys.Add(securityKey);
     m_securityKeys = securityKeys.AsReadOnly();
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:InfoCardProofToken.cs


示例4: EncryptingCredentials

        /// <summary>
        /// Constructs an EncryptingCredentials with a security key, a security key identifier and
        /// the encryption algorithm.
        /// </summary>
        /// <param name="key">A security key for encryption.</param>
        /// <param name="keyIdentifier">A security key identifier for the encryption key.</param>
        /// <param name="algorithm">The encryption algorithm.</param>
        /// <exception cref="ArgumentNullException">When key is null.</exception>
        /// <exception cref="ArgumentNullException">When key identifier is null.</exception>
        /// <exception cref="ArgumentNullException">When algorithm is null.</exception>
        public EncryptingCredentials(SecurityKey key, SecurityKeyIdentifier keyIdentifier, string algorithm)
        {
            if (key == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
            }

            if (keyIdentifier == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("keyIdentifier");
            }

            if (string.IsNullOrEmpty(algorithm))
            {
                throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("algorithm");
            }

            //
            // It is possible that keyIdentifier is pointing to a token which 
            // is not capable of doing the given algorithm, we have no way verify 
            // that at this level.
            //
            _algorithm = algorithm;
            _key = key;
            _keyIdentifier = keyIdentifier;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:36,代码来源:EncryptingCredentials.cs


示例5: SigningCredentials

		public SigningCredentials (SecurityKey signingKey, string signatureAlgorithm, string digestAlgorithm, SecurityKeyIdentifier signingKeyIdentifier)
			: this (signingKey, signatureAlgorithm, digestAlgorithm)
		{
			if (signingKeyIdentifier == null)
				throw new ArgumentNullException ("signingKeyIdentifier");
			this.identifier = signingKeyIdentifier;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:SigningCredentials.cs


示例6: TryResolveSecurityKey

 public bool TryResolveSecurityKey(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
 {
     if (keyIdentifierClause == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("keyIdentifierClause");
     }
     return this.TryResolveSecurityKeyCore(keyIdentifierClause, out key);
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:8,代码来源:SecurityTokenResolver.cs


示例7: BinarySecretSecurityToken

		protected BinarySecretSecurityToken (string id, byte [] key, bool allowCrypto)
			: this (id, allowCrypto)
		{
			if (key == null)
				throw new ArgumentNullException ("key");
			this.key = key;

			SecurityKey [] arr = new SecurityKey [] {new InMemorySymmetricSecurityKey (key)};
			keys = new ReadOnlyCollection<SecurityKey> (arr);
		}
开发者ID:nickchal,项目名称:pash,代码行数:10,代码来源:BinarySecretSecurityToken.cs


示例8: SwtIssuerTokenResolver

		public SwtIssuerTokenResolver()
		{
			var signValue = ConfigurationManager.AppSettings[SigningKeyAppSetting];
			if (string.IsNullOrEmpty(signValue))
				throw new InvalidSecurityException(string.Format(
					"Required appSettings key '{0}' containing the 256-bit symmetric key for token signing was not found.",
					SigningKeyAppSetting));

			this.key = new InMemorySymmetricSecurityKey(Convert.FromBase64String(signValue));
		}
开发者ID:KonstantinDavidov,项目名称:mytestRep,代码行数:10,代码来源:SwtIssuerTokenResolver.cs


示例9: TryResolveSecurityKeyCore

		protected override bool TryResolveSecurityKeyCore (
			SecurityKeyIdentifierClause keyIdentifierClause,
			out SecurityKey key)
		{
			key = null;
			foreach (SecurityTokenResolver r in resolvers)
				if (r != null && r.TryResolveSecurityKey (keyIdentifierClause, out key))
					return true;
			return false;
		}
开发者ID:nickchal,项目名称:pash,代码行数:10,代码来源:UnionSecurityTokenResolver.cs


示例10: TryResolveSecurityKeyCore

 protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
 {
     SecurityToken token;
     if (this.TryResolveTokenCore(keyIdentifierClause, out token))
     {
         key = ((SecurityContextSecurityToken) token).SecurityKeys[0];
         return true;
     }
     key = null;
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:SecurityContextSecurityTokenResolver.cs


示例11: TryResolveSecurityKeyCore

		protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
		{
			// We pass ourselves a SwtSecurityKeyClause from the SwtSecurityTokenHandler on ValidateToken.
			var nameClause = keyIdentifierClause as SwtSecurityKeyClause;

			// If it wasn't us passing the clause, let the base class handle other built-in scenarios (i.e. X509)
			if (nameClause == null)
				return base.TryResolveSecurityKeyCore(keyIdentifierClause, out key);

			key = this.key;
			return true;
		}
开发者ID:KonstantinDavidov,项目名称:mytestRep,代码行数:12,代码来源:SwtIssuerTokenResolver.cs


示例12: TryResolveSecurityKeyCore

        protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
        {
            key = null;
            var swtClause = keyIdentifierClause as WebTokenSecurityKeyClause;

            string value;
            if (_signingKeys.TryGetValue(swtClause.Issuer.ToLowerInvariant(), out value))
            {
                key = new InMemorySymmetricSecurityKey(Convert.FromBase64String(value));

                return true;
            }

            return false;
        }
开发者ID:bencoveney,项目名称:Thinktecture.IdentityModel.40,代码行数:15,代码来源:WebTokenIssuerTokenResolver.cs


示例13: TryResolveSecurityKeyCore

        protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
        {
            key = null;
            CustomTokenKeyIdentifierClause keyClause = keyIdentifierClause as CustomTokenKeyIdentifierClause;
            if (keyClause != null)
            {
                string base64Key = null;
                _keys.TryGetValue(keyClause.Audience, out base64Key);
                if (!string.IsNullOrEmpty(base64Key))
                {
                    key = new InMemorySymmetricSecurityKey(Encoding.UTF8.GetBytes(base64Key));
                    return true;
                }
            }

            return false;
        }
开发者ID:driverpt,项目名称:SI-1213SI,代码行数:17,代码来源:CustomIssuerTokenResolver.cs


示例14: NamedKeySecurityToken

        /// <summary>
        /// Initializes a new instance of the <see cref="NamedKeySecurityToken"/> class that contains a single <see cref="SecurityKey"/>.
        /// </summary>
        /// <param name="name">A name for the <see cref="SecurityKey"/>.</param>
        /// <param name="id">the identifier for this token.</param>
        /// <param name="key">A <see cref="SecurityKey"/></param>
        /// <exception cref="ArgumentNullException">if 'name' is null or whitespace.</exception>
        /// <exception cref="ArgumentNullException">if 'id' is null or whitespace.</exception>
        /// <exception cref="ArgumentNullException">if 'key' is null.</exception>
        public NamedKeySecurityToken(string name, string id, SecurityKey key)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException("name");

            if (string.IsNullOrWhiteSpace(id))
                throw new ArgumentNullException("id");

            if (key == null)
                throw new ArgumentNullException("key");

            this.id = id;
            this.name = name;
            this.securityKeys = new List<SecurityKey>{key};
            this.validFrom = DateTime.UtcNow;

        }
开发者ID:richardschneider,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:26,代码来源:NamedKeySecurityToken.cs


示例15: TryResolveSecurityKeyCore

        /// <summary>
        /// Override of the base class. Resolves the given SecurityKeyIdentifierClause to a 
        /// SecurityKey.
        /// </summary>
        /// <param name="keyIdentifierClause">The Clause to be resolved.</param>
        /// <param name="key">The resolved SecurityKey</param>
        /// <returns>True if successfully resolved.</returns>
        /// <exception cref="ArgumentNullException">Input argument 'keyIdentifierClause' is null.</exception>
        protected override bool TryResolveSecurityKeyCore( SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key )
        {
            if ( keyIdentifierClause == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "keyIdentifierClause" );
            }

            key = null;
            foreach ( SecurityTokenResolver tokenResolver in _tokenResolvers )
            {
                if ( tokenResolver.TryResolveSecurityKey( keyIdentifierClause, out key ) )
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:26,代码来源:AggregateTokenResolver.cs


示例16: CreateHeaderAsync

        /// <summary>
        /// Creates the JWT header
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="credential">The credentials.</param>
        /// <returns>The JWT header</returns>
        protected virtual async Task<JwtHeader> CreateHeaderAsync(Token token, SecurityKey key)
        {
            JwtHeader header = null;

#if DOTNET5_4
            header = new JwtHeader(new SigningCredentials(key, SecurityAlgorithms.RsaSha256Signature));
#elif NET451
            header = new JwtHeader(new SigningCredentials(key, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest));

            var x509key = key as X509SecurityKey;
            if (x509key != null)
            {
                header.Add("kid", await _keyService.GetKidAsync(x509key.Certificate));
                header.Add("x5t", await _keyService.GetKidAsync(x509key.Certificate));
            }
#endif

            return header;
        }
开发者ID:haoas,项目名称:IdentityServer4,代码行数:25,代码来源:DefaultTokenSigningService.cs


示例17: TryResolveSecurityKeyCore

        /// <summary>
        /// Resolves the given SecurityKeyIdentifierClause to a SecurityKey.
        /// </summary>
        /// <param name="keyIdentifierClause">SecurityKeyIdentifierClause to resolve</param>
        /// <param name="key">The resolved SecurityKey.</param>
        /// <returns>True if successfully resolved.</returns>
        /// <exception cref="ArgumentNullException">The input argument 'keyIdentifierClause' is null.</exception>
        protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
        {
            if (keyIdentifierClause == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("keyIdentifierClause");
            }

            key = null;
            EncryptedKeyIdentifierClause encryptedKeyIdentifierClause = keyIdentifierClause as EncryptedKeyIdentifierClause;
            if (encryptedKeyIdentifierClause != null)
            {
                SecurityKeyIdentifier keyIdentifier = encryptedKeyIdentifierClause.EncryptingKeyIdentifier;
                if (keyIdentifier != null && keyIdentifier.Count > 0)
                {
                    for (int i = 0; i < keyIdentifier.Count; i++)
                    {
                        SecurityKey unwrappingSecurityKey = null;
                        if (TryResolveSecurityKey(keyIdentifier[i], out unwrappingSecurityKey))
                        {
                            byte[] wrappedKey = encryptedKeyIdentifierClause.GetEncryptedKey();
                            string wrappingAlgorithm = encryptedKeyIdentifierClause.EncryptionMethod;
                            byte[] unwrappedKey = unwrappingSecurityKey.DecryptKey(wrappingAlgorithm, wrappedKey);
                            key = new InMemorySymmetricSecurityKey(unwrappedKey, false);
                            return true;
                        }
                    }
                }
            }
            else
            {
                SecurityToken token = null;
                if (TryResolveToken(keyIdentifierClause, out token))
                {
                    if (token.SecurityKeys.Count > 0)
                    {
                        key = token.SecurityKeys[0];
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:50,代码来源:X509CertificateStoreTokenResolver.cs


示例18: SigningCredentials

 public SigningCredentials(SecurityKey signingKey, string signatureAlgorithm, string digestAlgorithm, SecurityKeyIdentifier signingKeyIdentifier)
 {
     if (signingKey == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("signingKey"));
     }
     if (signatureAlgorithm == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("signatureAlgorithm"));
     }
     if (digestAlgorithm == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("digestAlgorithm"));
     }
     this.signingKey = signingKey;
     this.signatureAlgorithm = signatureAlgorithm;
     this.digestAlgorithm = digestAlgorithm;
     this.signingKeyIdentifier = signingKeyIdentifier;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:SigningCredentials.cs


示例19: TryResolveSecurityKeyCore

 protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key)
 {
     bool flag = false;
     key = null;
     flag = this.tokenResolver.TryResolveSecurityKey(keyIdentifierClause, false, out key);
     if (!flag && (this.outOfBandTokenResolvers != null))
     {
         for (int i = 0; i < this.outOfBandTokenResolvers.Count; i++)
         {
             flag = this.outOfBandTokenResolvers[i].TryResolveSecurityKey(keyIdentifierClause, out key);
             if (flag)
             {
                 break;
             }
         }
     }
     if (!flag)
     {
         flag = System.ServiceModel.Security.SecurityUtils.TryCreateKeyFromIntrinsicKeyClause(keyIdentifierClause, this, out key);
     }
     return flag;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:AggregateTokenResolver.cs


示例20: CreateProvider

        private SignatureProvider CreateProvider(SecurityKey key, string algorithm, bool willCreateSignatures)
        {
            _Logger?.LogDebug($"Creating {algorithm} provider for {key.KeyId} for {(willCreateSignatures ? "signing" : "verifying")}");
            if (key == null)
                throw new ArgumentNullException(nameof(key));
            if (string.IsNullOrWhiteSpace(algorithm))
                throw new ArgumentNullException(nameof(algorithm));

            //AsymmetricSecurityKey asymmetricSecurityKey = key as AsymmetricSecurityKey;
            //if (asymmetricSecurityKey != null)
            //    return new AsymmetricSignatureProvider(asymmetricSecurityKey, algorithm, willCreateSignatures, this.AsymmetricAlgorithmResolver);
            SymmetricSecurityKey symmetricSecurityKey = key as SymmetricSecurityKey;
            if (symmetricSecurityKey != null)
                return new SymmetricSignatureProvider(symmetricSecurityKey, algorithm);
            JsonWebKey jsonWebKey = key as JsonWebKey;
            if (jsonWebKey != null && jsonWebKey.Kty != null)
            {
                //if (jsonWebKey.Kty == "RSA" || jsonWebKey.Kty == "EC")
                //    return new AsymmetricSignatureProvider(key, algorithm, willCreateSignatures, this.AsymmetricAlgorithmResolver);
                if (jsonWebKey.Kty == "oct")
                    return new SymmetricSignatureProvider(key, algorithm);
            }
            throw new ArgumentException($"{typeof(SignatureProvider)} supports: '{typeof(SecurityKey)}' of types: '{typeof(AsymmetricSecurityKey)}' or '{typeof(AsymmetricSecurityKey)}'. SecurityKey received was of type: '{key.GetType()}'.");
        }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:24,代码来源:MonoFriendlyCryptoProviderFactory.cs



注:本文中的System.IdentityModel.Tokens.SecurityKey类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tokens.SecurityKeyIdentifierClause类代码示例发布时间:2022-05-26
下一篇:
C# Tokens.SamlSerializer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap